Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can make a FileProvider available to other applications?

Is it possible to have a FileProvider available to other applications ?

manifest.xml

...
 <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.example.myapp.fileprovider"
        android:exported="true"
        android:grantUriPermissions="false"
        android:permission="com.example.filesvisible.permission.READ" >
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filespath" />
    </provider>
...

From the doc:

false: The provider is not available to other applications. Set android:exported="false" to limit access to the provider to your applications. Only applications that have the same user ID (UID) as the provider will have access to it.

I've tried to set exported to true but I got this exception Unable to get provider android.support.v4.content.FileProvider: java.lang.SecurityException: Provider must not be exported Why I can't export a FileProvider ?

like image 507
M'hamed Avatar asked Jun 06 '14 21:06

M'hamed


People also ask

How do I use FileProvider?

To make FileProvider work follow these three steps: Define the FileProvider in your AndroidManifest file. Create an XML file that contains all paths that the FileProvider will share with other applications. Bundle a valid URI in the Intent and activate it.

How do I install FileProvider on Android?

fileprovider . To get a content URI for the file default_image. jpg in the images/ subdirectory of your internal storage add the following code: File imagePath = new File(Context.

What is provider in manifest?

A content provider is a subclass of ContentProvider that supplies structured access to data managed by the application. All content providers in your application must be defined in a <provider> element in the manifest file; otherwise, the system is unaware of them and doesn't run them.


1 Answers

Is it possible to have a FileProvider available to other applications ?

Yes. That is usually the point.

Why I can't export a FileProvider ?

Because that is not how you use a FileProvider.

The point behind FileProvider is to give select access to files to third-party apps. You can do this by FLAG_GRANT_READ_URI_PERMISSION and/or FLAG_GRANT_WRITE_URI_PERMISSION, in the Intent that you use to pass one of your provider's Uri values to the third-party app (e.g., via an ACTION_VIEW Intent used with startActivity()).

Also see the training guide on sharing files.

like image 146
CommonsWare Avatar answered Sep 29 '22 12:09

CommonsWare