无法在API 30中找到Content Provider [英] 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.
问题:我的解析内容提供程序的应用程序无法在具有API 30的模拟器中运行.错误:
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
如果我使用API 26、27、28和29,那么没问题.
If I use APIs 26,27,28 and 29 then there is no problem.
带有ContentProvider的应用中的AndroidManifest.xml:
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:
AndroidManifest.xml in client app :
<manifest>
...
<uses-permission android:name="MyProvider._READ_PERMISSION" />
...
</manifest>
如果我尝试在同一应用程序中解析Content Provider,则可以使用.
If I try to resolve Content Provider in the same app, it works.
如果我在客户端代码中使用 packageManager.getInstalledPackages(PackageManager.GET_PROVIDERS)
来获取现有提供程序的列表,那么对于API [26,29],我可以在列表中看到我的提供程序.如果我在API 30中运行此代码,则我的提供程序不在列表中.
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.
似乎API 30中的某些内容与ContentProvider的注册有关.但是我找不到.
It seems that something was changed in API 30 related to registration of ContentProvider. However I can't find what.
推荐答案
我的自定义ContentProvider无法在具有API 30的模拟器上运行的原因是
The reason my custom ContentProvider doesn't work on Emulator with API 30 is Package visibility in Android 11+
要解决,我已在客户端的AndroidManifest.xml中添加以下< queries>
元素:
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>
其中 com.a52.datafeeder01
是定义自定义ContentProvider的程序包名称.
where com.a52.datafeeder01
is the package name where custom ContentProvider is defined.
这篇关于无法在API 30中找到Content Provider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!