benlau / androidnative.pri

Calling Android functions from Qt without using JNI
Apache License 2.0
103 stars 15 forks source link

D AndroidNative: android.os.FileUriExposedException: file:///storage/emulated/0/DCIM/2018-06-05%2020.19.03.jpg exposed beyond app through ClipData.Item.getUri() #16

Open mjamroz opened 6 years ago

mjamroz commented 6 years ago

When im trying to use it on android 25, then i got the error as in the title. Is there any hope it will be working for the newest targets?

anyway, great package. thank you!

rmallah commented 6 years ago

@mjamroz can you please tell which function is being called , we shall try to fix it.

mjamroz commented 6 years ago

@rmallah Hi, thanks for your answer.

Im calling ImagePicker.takePhoto() to get that error. ImagePicker.pickImage() is working correctly.

rmallah commented 6 years ago

Thanks for the response. Shall see it soon.

regds mallah.

On Wed, Jun 6, 2018 at 8:08 PM, Michal Jamroz notifications@github.com wrote:

@rmallah https://github.com/rmallah Hi, thanks for your answer.

Im calling ImagePicker.takePhoto() to get that error. ImagePicker.pickImage() is working correctly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/benlau/androidnative.pri/issues/16#issuecomment-395092125, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHZuddEVdjm1y1Ef4MH_6OPDGz26Nm6ks5t5-ltgaJpZM4UbVij .

rmallah commented 6 years ago

Hi @mjamroz ,

ImagePicker.takePhoto() is also included in the demo program. can you compile the demo program and see if the "Image Picker" Component as displayed in home of the demo app works.

please note you will have to install quickandroid to compile the demo program,

in the project folder "androidnative.pri/examples/androidnativeexample" by run

$ qpm install com.github.benlau.quickandroid@0.1.7

(you have to install qpm if you do not have already)

I did these and in Android-25 ie version: 7.1.x it does work.

regds mallah.

mjamroz commented 6 years ago

I tried it.

I tested directly of quickandroid

$ qpm install com.github.benlau.quickandroid@0.1.7 opened quickandroidexample.pro in qtcreator selected Android_for_armeabi_v7a_GCC_4_9_Qt_5_9_0_for_Android_armv7-Debug to compile set API 25 in androidmanifest.xml i had to replace gradle version in gradle-wrapper.properties, because

> Gradle version 2.2 is required. Current version is 3.4. If using the gradle wrapper, try editing the distributionUrl in /home/nme/te/vendor/com/github/benlau/quickandroid/examples/build-quickandroidexample-Android_for_armeabi_v7a_GCC_4_9_Qt_5_9_0_for_Android_armv7-Debug/android-build/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip

compiled and opened on my motorola. After clicking icon with camera i got the same error as in my own application:

D quickandroid.ImagePicker: takePhoto : file:///storage/emulated/0/DCIM/2018-06-06%2020.46.11.jpg
D QuickAndroid: android.os.FileUriExposedException: file:///storage/emulated/0/DCIM/2018-06-06%2020.46.11.jpg exposed beyond app through ClipData.Item.getUri()
D QuickAndroid:     at android.os.StrictMode.onFileUriExposed(StrictMode.java:1813)
D QuickAndroid:     at android.net.Uri.checkFileUriExposed(Uri.java:2366)
D QuickAndroid:     at android.content.ClipData.prepareToLeaveProcess(ClipData.java:845)
D QuickAndroid:     at android.content.Intent.prepareToLeaveProcess(Intent.java:8989)
D QuickAndroid:     at android.content.Intent.prepareToLeaveProcess(Intent.java:8974)
D QuickAndroid:     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1583)
D QuickAndroid:     at android.app.Activity.startActivityForResult(Activity.java:4229)
D QuickAndroid:     at android.app.Activity.startActivityForResult(Activity.java:4187)
D QuickAndroid:     at quickandroid.ImagePicker.takePhoto(ImagePicker.java:89)
D QuickAndroid:     at quickandroid.ImagePicker$1.onDispatched(ImagePicker.java:41)
D QuickAndroid:     at quickandroid.SystemDispatcher.emit(SystemDispatcher.java:155)
D QuickAndroid:     at quickandroid.SystemDispatcher.dispatch(SystemDispatcher.java:66)

Selecting photo from storage works (the same like in my own app), only takePhoto() crashes.

I tested also as you suggested, getting the same error

git clone https://github.com/benlau/androidnative.pri.git
cd androidnative.pri/examples/androidnativeexample/
qpm install com.github.benlau.quickandroid@0.1.7 
opened pro in qt creator
set API 25 in androidmanisfest
compiled with Android_for_armeabi_v7a_GCC_4_9_Qt_5_9_0_for_Android_armv7-Debug

... and clicking icon to open native camera, i got:

D androidnative.ImagePicker: takePhoto : file:///storage/emulated/0/DCIM/2018-06-06%2020.57.27.jpg
D AndroidNative: android.os.FileUriExposedException: file:///storage/emulated/0/DCIM/2018-06-06%2020.57.27.jpg exposed beyond app through ClipData.Item.getUri()
D AndroidNative:    at android.os.StrictMode.onFileUriExposed(StrictMode.java:1813)
D AndroidNative:    at android.net.Uri.checkFileUriExposed(Uri.java:2366)
D AndroidNative:    at android.content.ClipData.prepareToLeaveProcess(ClipData.java:845)
D AndroidNative:    at android.content.Intent.prepareToLeaveProcess(Intent.java:8989)
D AndroidNative:    at android.content.Intent.prepareToLeaveProcess(Intent.java:8974)
D AndroidNative:    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1583)
D AndroidNative:    at android.app.Activity.startActivityForResult(Activity.java:4229)
D AndroidNative:    at android.app.Activity.startActivityForResult(Activity.java:4187)
D AndroidNative:    at androidnative.ImagePicker.takePhoto(ImagePicker.java:89)
D AndroidNative:    at androidnative.ImagePicker$1.onDispatched(ImagePicker.java:41)
D AndroidNative:    at androidnative.SystemDispatcher.emit(SystemDispatcher.java:155)
D AndroidNative:    at androidnative.SystemDispatcher.dispatch(SystemDispatcher.java:66)

If you need some more info/tests/etc. let me know. I will be happy to help.

rmallah commented 6 years ago

Relevant Discussion:

https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed/38858040#38858040

we shall try to improve upon it. I shall have access to my android 7.1 handset after a couple of hours.

regds mallah.

mjamroz commented 6 years ago

I would say it will be painful to replace that since qt/qml uses file://. Maybe rather solution from https://stackoverflow.com/a/42437379 ?

rmallah commented 6 years ago

@mjamroz it should be possible to find a proper solution . I don't feel its related to usage of file:// by qt/qml. I am working on it should be able to find a solution based on https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en which is essentially the same info.

thanks for reporting it . For the time being you may use some workaround. i shall be able to see to it only after a few days.

regds mallah.

parshwa1596 commented 4 years ago

android.os.FileUriExposedException: file:///storage/emulated/0/Documents/Patidar.pdf exposed beyond app through Intent.getData() at android.os.StrictMode.onFileUriExposed(StrictMode.java:1960) at android.net.Uri.checkFileUriExposed(Uri.java:2362) at android.content.Intent.prepareToLeaveProcess(Intent.java:9901) at android.content.Intent.prepareToLeaveProcess(Intent.java:9853) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1612) at android.app.Activity.startActivityForResult(Activity.java:4555) at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767) at android.app.Activity.startActivityForResult(Activity.java:4513) at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:754) at android.app.Activity.startActivity(Activity.java:4874) at android.app.Activity.startActivity(Activity.java:4842) at com.patidar.marriagebureau.Activities.Printprofile.previewPdf(Printprofile.java:501) at com.patidar.marriagebureau.Activities.Printprofile.createPdf(Printprofile.java:486) at com.patidar.marriagebureau.Activities.Printprofile.createPdfWrapper(Printprofile.java:416) at com.patidar.marriagebureau.Activities.Printprofile.access$000(Printprofile.java:65) at com.patidar.marriagebureau.Activities.Printprofile$1.onClick(Printprofile.java:171)

i got these error what can i do