Compiling for Android N I\'ve faced an issue of FileProvider
. I need to let user to pick image from gallery/take picture with camera then crop it to square.
Agreed with @x-code's answer you are not described very clear about issue although if you try to access another app's internal data then you must have permissions to do so.
Files that rightfully belong to your app and should be deleted when the user uninstalls your app. Although these files are technically accessible by the user and other apps because they are on the external storage, they are files that realistically don't provide value to the user outside your app.
Actually i have found on documentation that SDK version 24 is now updated with many schemes and have massive changes in working with Files,from documentation the problem with file:// is described as..
Due to security reasons it is highly recommended to use Content:// instead of using file:// so basically use ContentProvider instead of FileProvider.
A simple example of using it is below,
in AndroidMenifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<application
...
<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>
</application>
</manifest>
And then 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
.
res/xml/provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
now to use it,
Uri photoURI = FileProvider.getUriForFile(MainActivity.this,
BuildConfig.APPLICATION_ID + ".provider",
createImageFile());
I have taken this from this blog so please read it for full understanding.Hope it helps everyone.
I think this question is based on a misunderstanding.
The purpose of a FileProvider is to grant access (to an external app), to a file that your app already controls.
You will never succeed in using your own file provider to gain access to a file owned by an external app.
It is up to the external app to grant you that access using a file provider, if it chooses to.
That seems to be what the question is asking for. If I have not understood your question, let me know, but if I do understand it, what you are trying to do just won't work.