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 #2

Open
swabbass opened this issue Sep 13, 2017 · 5 comments
Open

FileUriExposedException #2

swabbass opened this issue Sep 13, 2017 · 5 comments

Comments

@swabbass
Copy link

when try to make share we got this exception ...
android 8.0 ...it will occur on 7.0 also with build target 25.0.3

@balsikandar
Copy link
Collaborator

is it possible to share trace in any case i'll look into this

@RocketRider
Copy link
Contributor

You are using a file uri to open the log file.

This is not allowed on Android 7+ anymore:
https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed

@rgocal
Copy link

rgocal commented Oct 17, 2019

Was this fixed in the library

@rgocal
Copy link

rgocal commented Oct 18, 2019

How to fix

Create an xml file(Path: res\xml) provider_paths.xml

Add a Provider in AndroidManifest.xml

<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>

If you are using androidx, the FileProvider path should be:

android:name="androidx.core.content.FileProvider"

and replace

Uri uri = Uri.fromFile(fileImagePath);
to

Uri uri = FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID + ".provider",fileImagePath);
While you're including the URI with an Intent make sure to add below line:

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

@rayworks
Copy link

rayworks commented Jul 27, 2020

Got the same issue (V1.1.0 on OS 9.0) :

AndroidRuntime E FATAL EXCEPTION: main
E android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.your-app.pkgname/files/crashReports/2020-07-27%2017%3A14%3A53_crash.txt exposed beyond app through ClipData.Item.getUri()
E at android.os.StrictMode.onFileUriExposed(StrictMode.java:1978)
E at android.net.Uri.checkFileUriExposed(Uri.java:2371)
E at android.content.ClipData.prepareToLeaveProcess(ClipData.java:963)
E at android.content.Intent.prepareToLeaveProcess(Intent.java:10228)
E at android.content.Intent.prepareToLeaveProcess(Intent.java:10234)
E at android.content.Intent.prepareToLeaveProcess(Intent.java:10213)
E at android.app.Instrumentation.execStartActivity(Instrumentation.java:1669)
E at android.app.Activity.startActivityForResult(Activity.java:4586)
E at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActiv
ity.java:767)
E at android.app.Activity.startActivityForResult(Activity.java:4544)
E at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActiv
ity.java:754)
E at android.app.Activity.startActivity(Activity.java:4905)
E at android.app.Activity.startActivity(Activity.java:4873)
E at com.balsikandar.crashreporter.ui.LogMessageActivity.shareCrashReport(LogMes
sageActivity.java:82)
E at com.balsikandar.crashreporter.ui.LogMessageActivity.onOptionsItemSelected(L
ogMessageActivity.java:70)
E at android.app.Activity.onMenuItemSelected(Activity.java:3543)

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

Successfully merging a pull request may close this issue.

5 participants