fuselibs icon indicating copy to clipboard operation
fuselibs copied to clipboard

FileUriExposedException on Android >=8 using FuseJS/Camera

Open eksperts opened this issue 7 years ago • 4 comments

Reported on community.

Version fuse and OS

Fuse 1.5.0, macOS High Sierra

What do I expect?

I expect the URL of the photo to be printed on the console correctly when i use takephoto of Fuse.Camera Module

What's going on?

An exception thrown System.err: android.os.FileUriExposedException. This happens with Android versions > = 8.0. With earlier versions and with iOS it works properly. I have noticed that the cause is having added these specs in the project file:

"Android": {
    "SDK": {
      "BuildToolsVersion": "25.0.3",
      "CompileVersion": 25,
      "MinVersion": 16,
      "TargetVersion": 25
    }
  }

Reproduce the issue

Mainview.ux

<App>
	<JavaScript>
		
		var camera = require('FuseJS/Camera');
		var cameraRoll = require("FuseJS/CameraRoll");

		function takePhoto(){
			console.log("take photo");
			camera.takePicture(1920, 1080).then(function(newImage) {
		//HERE CRASH 
				console.log(newImage.path);
				}).catch(function(error) {
					cameraRoll.getImage().then(function(imageRoll) {
					console.log(imageRoll.path);
					}.bind(this),
						function(error) {
							console.log("error", JSON.stringify(error));
						});
			});
		}
		module.exports={takePhoto:takePhoto}
	</JavaScript>

	<Button Clicked="{takePhoto}" Text="Take photo"/>
</App>

*.unoproj

{
  "RootNamespace":"",
  "Packages": [
    "Fuse",
    "FuseJS",
    "Fuse.Camera",
    "Fuse.CameraRoll"
  ],
  "Includes": [
    "*"
  ],
  "Android": {
    "SDK": {
      "BuildToolsVersion": "25.0.3",
      "CompileVersion": 25,
      "MinVersion": 16,
      "TargetVersion": 25
    }
  }
}

EXCEPTION

System.err: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.sandos.precheckin/cache/images/IMG_696f3530-2789-419a-aa44-1f9a788925b9.jpg exposed beyond app through ClipData.Item.getUri()

01-09 18:23:22.701 22775 22775 W System.err: at android.os.StrictMode.onFileUriExposed(StrictMode.java:1960)
01-09 18:23:22.701 22775 22775 W System.err: at android.net.Uri.checkFileUriExposed(Uri.java:2348)
01-09 18:23:22.701 22775 22775 W System.err: at android.content.ClipData.prepareToLeaveProcess(ClipData.java:942)
01-09 18:23:22.701 22775 22775 W System.err: at android.content.Intent.prepareToLeaveProcess(Intent.java:9850)
01-09 18:23:22.701 22775 22775 W System.err: at android.content.Intent.prepareToLeaveProcess(Intent.java:9835)
01-09 18:23:22.701 22775 22775 W System.err: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1610)
01-09 18:23:22.702 22775 22775 W System.err: at android.app.Activity.startActivityForResult(Activity.java:4487)
01-09 18:23:22.702 22775 22775 W System.err: at android.app.Activity.startActivityForResult(Activity.java:4445)
01-09 18:23:22.702 22775 22775 W System.err: at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
01-09 18:23:22.702 22775 22775 W System.err: at com.foreign.Android.ActivityUtils.StartForResultJava72(ActivityUtils.java:55)
01-09 18:23:22.702 22775 22775 W System.err: at com.Bindings.ExternedBlockHost.StartForResultJava72(ExternedBlockHost.java:416)
01-09 18:23:22.702 22775 22775 W System.err: at com.Bindings.ExternedBlockHost.callUno_Uno_Permissions_Permissions_Succeeded60(Native Method)
01-09 18:23:22.702 22775 22775 W System.err: at com.foreign.Uno.Permissions.Permissions.permissionRequestSucceeded(Permissions.java:33)
01-09 18:23:22.702 22775 22775 W System.err: at com.Bindings.ExternedBlockHost.permissionRequestSucceeded(ExternedBlockHost.java:364)
01-09 18:23:22.703 22775 22775 W System.err: at com.fuse.Permissions.onRequestPermissionsResult(Permissions.java:93)
01-09 18:23:22.703 22775 22775 W System.err: at com.fuse.App.onRequestPermissionsResult(App.java:260)
01-09 18:23:22.703 22775 22775 W System.err: at com.sandos.precheckin.SandosCheckin.onRequestPermissionsResult(SandosCheckin.java:133)
01-09 18:23:22.703 22775 22775 W System.err: at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7419)
01-09 18:23:22.703 22775 22775 W System.err: at android.app.Activity.dispatchActivityResult(Activity.java:7270)
01-09 18:23:22.703 22775 22775 W System.err: at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
01-09 18:23:22.703 22775 22775 W System.err: at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
01-09 18:23:22.703 22775 22775 W System.err: at android.app.ActivityThread.-wrap19(Unknown Source:0)
01-09 18:23:22.703 22775 22775 W System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
01-09 18:23:22.703 22775 22775 W System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
01-09 18:23:22.704 22775 22775 W System.err: at android.os.Looper.loop(Looper.java:164)
01-09 18:23:22.704 22775 22775 W System.err: at android.app.ActivityThread.main(ActivityThread.java:6494)
01-09 18:23:22.704 22775 22775 W System.err: at java.lang.reflect.Method.invoke(Native Method)
01-09 18:23:22.704 22775 22775 W System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
01-09 18:23:22.704 22775 22775 W System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)))))

Useful reference (see the suggestion to use content: instead of file:): https://developer.android.com/reference/android/os/FileUriExposedException.html Since this causes a hard crash on builds, I reckon this might be quite an important one.

eksperts avatar Jan 11 '18 11:01 eksperts

The forum thread ISSUE CAMERA CRASH posted by toto007 was linked to this issue.

fusebuild avatar Jan 11 '18 11:01 fusebuild

Any progress on this?

shnupta avatar Aug 05 '18 19:08 shnupta

Any progress on this? I can't take a picture on my apps and now the minimum version is SDK 26!

I see https://github.com/fuse-open/fuselibs/pull/1207 but I don't know how can implement it to Fuse.ImageTools!

ckarmy avatar Sep 26 '18 19:09 ckarmy

I fully agree with ckarmy

francescocalculli avatar Oct 01 '18 18:10 francescocalculli