Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUriExposedException in Android N with Camera #13

Closed
martarodriguezm opened this issue Jun 29, 2016 · 4 comments
Closed

FileUriExposedException in Android N with Camera #13

martarodriguezm opened this issue Jun 29, 2016 · 4 comments

Comments

@martarodriguezm
Copy link

martarodriguezm commented Jun 29, 2016

Hi,

I have tried this library in my Nexus 6P with the preview of Android N, and it is working fine with Gallery but when selecting Camera source, it throws a FileUriExposedException.
This is the log:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com/com.mlsdev.rximagepicker.HiddenActivity}: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com/files/20160629_1123251566595922.jpg exposed beyond app through ClipData.Item.getUri()
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2692)
                                                                            at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:154)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:6044)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                                                                         Caused by: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com/files/20160629_1123251566595922.jpg exposed beyond app through ClipData.Item.getUri()
                                                                            at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
                                                                            at android.net.Uri.checkFileUriExposed(Uri.java:2346)
                                                                            at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
                                                                            at android.content.Intent.prepareToLeaveProcess(Intent.java:8909)
                                                                            at android.content.Intent.prepareToLeaveProcess(Intent.java:8894)
                                                                            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
                                                                            at android.app.Activity.startActivityForResult(Activity.java:4223)
                                                                            at android.app.Activity.startActivityForResult(Activity.java:4182)
                                                                            at com.mlsdev.rximagepicker.HiddenActivity.handleIntent(HiddenActivity.java:105)
                                                                            at com.mlsdev.rximagepicker.HiddenActivity.onCreate(HiddenActivity.java:36)
                                                                            at android.app.Activity.performCreate(Activity.java:6658)
                                                                            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2584)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2692) 
                                                                            at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                            at android.os.Looper.loop(Looper.java:154) 
                                                                            at android.app.ActivityThread.main(ActivityThread.java:6044) 
                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

targetSdkVersion 24

The reason of this error is that file:// uri scheme no more supported because the security is exposed.
Here you have the google issue: link

@martarodriguezm martarodriguezm changed the title FileUriExposedException in Android M with Camera FileUriExposedException in Android N with Camera Jun 29, 2016
@Frederikos
Copy link
Member

Frederikos commented Jun 30, 2016

@marta-rodriguez
Ok. Will check this after release of Android N.

@Frederikos
Copy link
Member

Apply this fix in 1.1.9

@martarodriguezm
Copy link
Author

Great, I'll try, thanks!

@KaluKhan
Copy link

Step 1.
Add entry of Provider in your menifest file :
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider>
Step 2.
create a provider_paths.xml file in xml folder under res folder. Folder may be needed to create if it doesn't exist. The content of the file is shown below. It describes that we would like to share access to the External Storage at root folder (path=".") with the name external_files.
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="external_files" path="."/> </paths>
Step 3.
The final step is to change the line of code below in
Uri photoURI = Uri.fromFile(createImageFile());
to
Uri photoURI = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".my.package.name.provider", createImageFile());
Please refer, full code and solution has been explained here .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants