Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: "Element intent-filter is not allowed here" inside <provider>?

At http://developer.android.com/guide/topics/providers/document-provider.html#manifest it is shown how to register a custom document provider in the manifest:

<manifest... >
    ...
    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="19" />
        ....
        <provider
            android:name="com.example.android.storageprovider.MyCloudProvider"
            android:authorities="com.example.android.storageprovider.documents"
            android:grantUriPermissions="true"
            android:exported="true"
            android:permission="android.permission.MANAGE_DOCUMENTS"
            android:enabled="@bool/atLeastKitKat">
            <intent-filter>
                <action android:name="android.content.action.DOCUMENTS_PROVIDER" />
            </intent-filter>
        </provider>
    </application>

</manifest>

This <intent-filter> element is necessary here, but Android Studio complains with:

Element intent-filter is not allowed here

and the documentation for the provider element seems to indicate so as well:

CAN CONTAIN:
<meta-data> 
<grant-uri-permission> 
<path-permission>

Is this an Android Studio and documentation bug or am I missing something?

like image 774
fornwall Avatar asked Apr 22 '16 01:04

fornwall


1 Answers

You're not missing anything; Android Studio and the documentation are incorrect. Providers are subject to discovery through intent matching, just like any other component.

Android finds document providers using code like this:

Intent i = new Intent(DocumentsContract.PROVIDER_INTERFACE);

List<ResolveInfo> providers = packageManager.queryIntentContentProviders(i, 0);

like image 81
j__m Avatar answered Sep 25 '22 13:09

j__m