内容提供者 INSTALL_FAILED_CONFLICTING_PROVIDER(将内容提供者作为单独的 apk 安装) [英] Content Provider INSTALL_FAILED_CONFLICTING_PROVIDER (installing content provider as a separate apk)

查看:52
本文介绍了内容提供者 INSTALL_FAILED_CONFLICTING_PROVIDER(将内容提供者作为单独的 apk 安装)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序使用相同的内容提供程序,但我不能在两个应用程序中放置相同的内容提供程序 - 它显示 INSTALL_FAILED_CONFLICTING_PROVIDER 错误.因此,我将我的内容提供程序放在了第三个 .apk 中,并从两个应用程序中使用了它,并且运行良好.

I have two applications which use the same content provider, but I can't put the same content provider in both applications- it shows INSTALL_FAILED_CONFLICTING_PROVIDER error. So I have put my content provider in a 3rd .apk and used this from two applications and it is working well.

现在的问题是 - 必须先安装内容提供程序 apk,然后才能在设备上安装这两个应用程序中的任何一个.否则,在安装过程中会显示 Provider not found 错误.

Now the problem is- The content provider apk must be installed before any of those two apps can be installed on the device. Otherwise, it shows Provider not found error during installation.

那么,如何确保在安装任何其他 apk 之前安装了提供程序 apk?

So, how can I ensure that the provider apk is installed before any of the other apks is installed?

有没有办法将内容提供程序 apk 分别与其他两个 apk 合并,这样它们将作为两个应用程序一起安装并且不会显示 INSTALL_FAILED_CONFLICTING_PROVIDER 错误?

Is there a way to merge the content provider apk with both of the other apks separately, so they will be installed together as two applications and won't show INSTALL_FAILED_CONFLICTING_PROVIDER error?

我需要将内容提供程序 apk 与两个应用程序合并,因为用户可能不会同时安装这两个应用程序,或者可能将它们都安装在一个设备上.

I need to merge the content provider apk with both applications, because the user may not install both applications or may install them both on a single device.

推荐答案

我能想到的一个解决方案是,让内容提供者成为具有不同 packageid 的两个应用程序的一部分.并使用 android:exported = true 将其导出.不过,两者可能使用相同的代码.

One solution i can think of is, make content provider part of both the applications with different packageid's internally.and export it using android:exported = true. Both might be using the same code though.

在应用程序开始时,您检查设备上是否存在其他内容提供者,如果存在,您就开始使用它,否则您将退回到本地内容提供者.当其他应用程序安装时,它可以做同样的检查.

At the start of the application you check if the other content provider exists on the device if it's there you start using it,otherwise you fallback to local content provider. when the other applicaton installs it can does the same check.

为了保护您的内容提供者免受其他人的侵害,您可以定义自定义权限来保护它,以便您的应用程序只能使用它,或者您也可以放置一些自定义身份验证,例如某些密钥来访问内容提供者.您可以在内容提供程序的所有方法中使用此身份验证代码.

To protect your cotent provider from everyone else, you can define a custom permission to protect it, so that your applications can only use it or you can also put some custom authentication like some secret key to access the content provider. you can have this authentication code in all methods of content provider.

这篇关于内容提供者 INSTALL_FAILED_CONFLICTING_PROVIDER(将内容提供者作为单独的 apk 安装)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆