Android Question FileUriExposedException while cropping a picture

rafaelmotaquintana

Active Member
Licensed User
With version 26 changes, I found another problem. This piece of code fails in version 24 and above

B4X:
    i.Initialize("com.android.camera.action.CROP", ParseUri("file://" & File.Combine(Main.rp.GetSafeDirDefaultExternal(""), PictureName)))
    i.SetType("image/*")
    i.PutExtra("crop", "true")
    i.PutExtra("aspectX", 1)
    i.PutExtra("aspectY", 1)
    i.PutExtra("output", ParseUri("file://" & File.Combine(Main.rp.GetSafeDirDefaultExternal(""), PictureName)))
    StartActivity(i)

It produce the following error:

android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.tropic.invoicefull/files/DEFAULT_1.jpg exposed beyond app through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
.
.
.

Its like camera function to crop can't have access to the GetSafeDirDefaultExternal("") folder. I don't know what to do.
I have searched and the above solution is all I have found.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top