Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - FileProvider - name must not be empty

Tags:

android

I have the following FileProvider in my manifest :

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.android.provider.DataSharing-1"
        android:exported="false"
        android:grantUriPermissions="true">

        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/paths"/>

    </provider>

I am getting the following exception on app launch :

 java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.IllegalArgumentException: Name must not be empty
        at android.app.ActivityThread.installProvider(ActivityThread.java:4793)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)
        at android.app.ActivityThread.access$1500(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.IllegalArgumentException: Name must not be empty
        at android.support.v4.content.FileProvider$SimplePathStrategy.addRoot(FileProvider.java:644)
        at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:587)
        at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:534)
        at android.support.v4.content.FileProvider.attachInfo(FileProvider.java:352)
        at android.app.ActivityThread.installProvider(ActivityThread.java:4790) ...

How do I resolve this ? Where did I miss specifying a name ?

Edit :

res/xml/paths.xml

<paths xmlns:android="http://schemas.android.com/apk/res/android">

    <files-path android:name="my_images" android:path="images/"/>
</paths>
like image 790
Jake Avatar asked Jun 08 '14 21:06

Jake


People also ask

What is fileprovider in Android Studio?

androidx.core.content.FileProvider. FileProvider is a special subclass of ContentProvider that facilitates secure sharing of files associated with an app by creating a content:// Uri for a file instead of a file:/// Uri. A content URI allows you to grant read and write access using temporary access permissions.

How do I create a file provider in Android?

Create FileProvider Steps. Declare FileProvider provider component in AndroidManifest.xml file. Create a share folder xml file to indicate which folder will be shared. 2.1 Define FileProvider In AndroidManifest.xml.

How to grant fileprovider access to other apps in Android?

You can use intent setFlags method to grant FileProvider access permission to other apps like below. If you set grantUriPermissions value to false, it will throw SecurityException (“Provider must grant uri permissions”). meta-data sub element : The provider meta-data sub element is used to specify the shared folder definition xml file.

How to make your app more secure using fileprovider?

Using FileProvider you can make your app files more secure in following ways. You can fully control which file to share to which app more accurately. Your app do not need to ask user to grant WRITE_EXTERNAL_STORAGE permission always. This can make your app more user friendly.


1 Answers

Remove the android: prefix from the attributes in your paths.xml file. It should look like:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="my_images" path="images/"/>
</paths>

(and you can probably get rid of the xmlns:android bit too, since it's not used, though I have it in one of mine, perhaps because Eclipse put it there when creating the file...)

like image 98
CommonsWare Avatar answered Oct 17 '22 00:10

CommonsWare