- java.lang.SecurityException: Permission Denial: opening provider androidx.core.content.FileProvider
- Java android security exception
- 5 Answers 5
- java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.content.GooglePhotosImageProvider
- 2 Answers 2
- Android OREO — java.lang.SecurityException: Failed to find provider for user 0; expected to find a valid ContentProvider for this authority
- 2 Answers 2
- SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider that is not exported from uid 10063 #173
- Comments
- misaochan commented Jul 12, 2016
- misaochan commented Jul 12, 2016
- nicolas-raoul commented Jul 12, 2016
- misaochan commented Jul 18, 2016 •
java.lang.SecurityException: Permission Denial: opening provider androidx.core.content.FileProvider
So I’ve been making these 2 apps and I want app 1 to be able to send pdf files to app 2. They’re both signed with different keys as app 1 should be usable by any other apps as well.
The way I want it to work is as follows. App 2 sends a startActivityForResult to app 1 with an intent including a Uri with a file from App 2s fileprovider. Then app 1 should take the Uri and write the pdf onto the file provided by app 2. Then going back to app 2 the file should be written onto the file owned by app 2 in the first place.
Put simply the app 2 should provide a file where app 1 should write the pdf.
So I have it all set up like that but when trying to access the file to write to it, I get the java.lang.SecurityException: Permission Denial: opening provider androidx.core.content.FileProvider error message.
Full Error Message: Permission Denial: opening provider androidx.core.content.FileProvider from ProcessRecord <511cc8 14209:com.eureka.documentscanneru0a159>(pid=14209, uid=10159) that is not exported from UID 10155
Code to copy the pdf’s:
The security exception is always thrown on the pfdTo = cr.openFileDescriptor(to, WRITE_ACCESS); line.
I’m 100% sure there is read and write access on the intent used to start the activity for result, and that there is read and write permissions granted on the external storage.
Any suggestions or help would be appreciated.
Источник
Java android security exception
In my app the user has the ability to take a photo or add a photo to the app. I’m getting crash reports of java.lang.SecurityException when the app tries to display the saved image in a ImageView
The line it errors on is
I’ve been unable to duplicate the error myself on either my device or on simulators, they all display the image fine.
The full code I’m using is
The output from the logs showing on my device ( 3 projects, one without an image)
Project: Test — Parsed: file:///storage/emulated/0/Android/data/com.desbrina.diamondpaintinglogbook/files/Pictures/20191111_1408166491573472523237896.jpg
Project: Test 3 — Parsed: content://com.android.providers.media.documents/document/image%3A1891
5 Answers 5
I think you are getting the Security exception on an Android Pie or later operating system. This is because on these systems you have to declare the path that your app wants to use.
Additionally, it is possible that your app is trying to get content from another app that requires permission like Google Photos requires:
From Api 24 , you can not access the File Uris directly. You need to use File authorities for the folder and then use
In AndroidManifes.xml
Add the following to application tag. In following packagename is BuildConfig.APPLICATION_ID
provider_paths.xml
This Exception usually is caused by using imageuri from third party app.Solution is to implement file provider.You can get many solution on how to implement fileprovider.
I suspect this is down to the permissions you’ve implemented in your AndroidManifest.xml file. If you are debugging on API Level 23 or higher version of android then you have to take the runtime permission for WRITE_EXTERNAL_STORAGE at runtime as Security exception occurs due to permission denied by device.
This is because at the new version Android 9 introduced a new FOREGROUND_SERVICE permission; the docs say:
Note: Apps that target Android 9 (API level 28) or higher and use foreground services must request the FOREGROUND_SERVICE permission . This is a normal permission, so the system automatically grants it to the requesting app. If an app that targets API level 28 or higher attempts to create a foreground service without requesting FOREGROUND_SERVICE , the system throws a SecurityException .
Just add the permission to the manifest and should do the trick, «in theory». Let us know!! Something like:
Let´s try to take that bounty: Do you hace these permission?:
Источник
java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.content.GooglePhotosImageProvider
All of the sudden, I started getting the following exception from devices running android 4.3 and above
My The code causing it is
EDIT: This is how I let the user pick a picture before calling the above method
Here is the OnActivityResult:
2 Answers 2
While adding the permission works for this particular content provider it won’t work if your data is delivered by other content providers (on Android there’s no guarantee you’ll get the data by a specific content provider unless you explicitly access that content provider).
The «final» solution to this problem can be found here:
Getting access with temporary permissions
You can access data in a content provider, even if you don’t have the proper access permissions, by sending an intent to an application that does have the permissions and receiving back a result intent containing «URI» permissions. These are permissions for a specific content URI that last until the activity that receives them is finished.
Since version 4.3 Android checks whether the receiving Activity is still running and if not throws the SecurityException. The determineCorrectScale is a static method so I assume it’s at least sometimes called outside the Activity life cycle. To fix this once and for all you need to retrieve the data from the content provider while the Activity is running. I don’t know the requirements for your app but if there’s no heavy lifting involved (like copying images from the content provider) then just do it on the ui thread. If heavy lifting is needed then use an AsyncTask started by the Activity but then you have to make sure the Activity doesn’t finish before the data has been retrieved (which might be tricky).
I didn’t just add that answer because I think it’s the correct one but because other developers might not be aware of this change introduced in 4.3/4.4 and might run into the same issue with other content providers.
Источник
Android OREO — java.lang.SecurityException: Failed to find provider for user 0; expected to find a valid ContentProvider for this authority
I defined the provider in the manifest file.
This is how I defined my authority
But when I ‘m trying to load the uri into an image view, I keep getting the below error.
java.io.FileNotFoundException: com.test.PhotoProvider/data/user/0/com.test/cache/cropped953508219.jpg: open failed: ENOENT (No such file or directory)
This is happening even on Follow
2 Answers 2
I have implemented from that link and it worked for me.
Here is your solution, Crate a class named PhotoProvider extending ContentProvider and automatically implemented its methods. Declare a static final String defining the authority, and finally implemented a static method returning our brand new Uri . Here is the whole class below:
ContentProvider authority is holded by CONTENT_PROVIDER_AUTHORITY.
Do NOT forget to return true in onCreate method.
Finally getPhotoUri(File file) method makes our day. You have t passed your File object to the method and get Uri with fromFile(file) just like I did above. Then You have to use an Uri.Builder and copy necessary fields from our illegal outputUri , and finally set authority as CONTENT_PROVIDER_AUTHORITY.
I actually imitate Uri.fromFile(file) method except setting a custom authority. Original method is like below in Uri class:
This method sets authority as Part.EMPTY so Android Oreo crashes saying it must have an non-exported ContentProvider defining an authority for all Uris.
Setting authority fixes the problem and helps Android to protect your data (photo in my case) from leaking to malicious apps.
Источник
SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider that is not exported from uid 10063 #173
Comments
misaochan commented Jul 12, 2016
Posted by Tommy Gildseth on 12 Jul:
The text was updated successfully, but these errors were encountered:
misaochan commented Jul 12, 2016
Wow, there are an awful lot of bugs involving Google Photos, and my StackOverflow thread isn’t yielding any answers. 🙁
nicolas-raoul commented Jul 12, 2016
Linking it here for the sake of findability: http://stackoverflow.com/q/38301605
misaochan commented Jul 18, 2016 •
Oof, another Google Photos crash just showed up. :/ I’ve been reading up as much as I can on it, and the only solution I can find seems to require a major overhaul of how the image data is passed around.
Apparently it is due to a permissions change by the google photos provider:
For security reasons, the permissions are temporary, so once the client app’s task stack is finished, the file is no longer accessible. You must get the file data when you receive the intent answer, in the onActivityResult method. Store a copy of the file data, because the file won’t be available anymore when onActivityResult returns.
For the time being, should we tell people that our app has issues integrating with Google Photos?
Источник