0

我在手机上有超过 5 个应用程序需要与内容提供者共享数据,并且每个应用程序首先安装,必须创建表和 URI,所以在所有应用程序中我应该在清单中声明提供程序,以授予应用程序初始化提供程序的权限. 但我收到安装错误:INSTALL_FAILED_CONFLICTING_PROVIDER 错误,我该如何解决这个问题?

4

2 回答 2

2

I have more than 5 applications on the phone that they need to share data with content provider

Most likely, this is not a good idea.

so in all applications I should declare provider in manifest, to give the application authority to initialize provider

That will not work.

But I got Installation error: INSTALL_FAILED_CONFLICTING_PROVIDER error

That is why that will not work.

how can I manage this problem ?

Assuming for the moment that this was a good idea, you could ship the app with the <provider> marked as android:enabled="false". Then, the first app could try to access the ContentProvider, and when it determines that nobody else has set up the ContentProvider, it can enable its own (see PackageManager and setComponentEnabledSetting()).

So, let us suppose that your five applications are named A, B, C, D, and E. A is installed first. The user runs it, A sees that there is no ContentProvider, and enables its own. The user proceeds to install B, C, D, and E, and they all use A's ContentProvider to store their data. The user now uninstalls A. B, C, D, and E will lose all their data, as their data goes away when A is uninstalled. The user, in all likelihood, will not appreciate this.

The only scenario in which that is a good idea is if B, C, D, and E are supposed to depend entirely upon A. In that case, B, C, D, and E do not need their own ContentProvider, as they can always use A's, and if A does not exist, that is the user's fault.

于 2013-01-19T22:30:06.127 回答
0

您应该像这样在每个应用程序的清单中定义提供程序:

android:authorities="com.app.SomeContentProvider${applicationId}"

您的提供商对于每个应用程序都是独一无二的,这一点很重要。

于 2015-10-29T00:04:28.860 回答