androidandroid-contentproviderandroid-contentresolver

Failed to find Content Provider in API 30


UPDATE: I have to completely change my question since I found more details related to my problem.

The problem: My app that resolves Content Provider doesn't work in Emulator with API 30. The error:

java.lang.SecurityException: Failed to find provider com.a52.datafeeder01.MyProvider for user 0; expected to find a valid ContentProvider for this authority

If I use APIs 26,27,28 and 29 then there is no problem.

AndroidManifest.xml in app with ContentProvider:

<manifest>
    <permission
        android:name="MyProvider._READ_PERMISSION"
        android:protectionLevel="normal" />
    <application>
        <activity>
        ...
        </activity>
        <provider android:name=".MyProvider"
            android:authorities="com.a52.datafeeder01.MyProvider"
            android:enabled="true"
            android:exported="true"
            android:readPermission="MyProvider._READ_PERMISSION"/>
    </application>
</manifest>

AndroidManifest.xml in client app :

<manifest>
...
    <uses-permission android:name="MyProvider._READ_PERMISSION" />
...
</manifest>

If I try to resolve Content Provider in the same app, it works.

If I use packageManager.getInstalledPackages(PackageManager.GET_PROVIDERS) in my client code to get list of existing providers then for APIs [26,29] I can see my provider in the list. If I run this code in API 30 my provider is not in the list.

It seems that something was changed in API 30 related to registration of ContentProvider. However I can't find what.


Solution

  • The reason my custom ContentProvider doesn't work on Emulator with API 30 is Package visibility in Android 11+

    To Fix my issue I've added following <queries> element into client's AndroidManifest.xml:

    <manifest>
    ...
        <queries>
            <package android:name="com.a52.datafeeder01" />
        </queries>
    ...
    </manifest>
    

    where com.a52.datafeeder01 is the package name where custom ContentProvider is defined.