INSTALL FAILED CONFLICTING PROVIDER问题完美解决方案

来源:互联网 发布:一辈子单身感受知乎 编辑:程序博客网 时间:2024/06/05 18:35

INSTALL FAILED CONFLICTING PROVIDER

在安装Android应用时出现INSTALL FAILED CONFLICTING PROVIDER问题,是不是感觉很抓狂呢,下面就跟大家分享一下出现这个问题的原因及解决方案。

问题原因

在Android中authority要求必须是唯一的,比如你在定义一个provider时需要为它指定一个唯一的authority。如果你在安装一个带有provider的应用时,系统会检查当前已安装应用的authority是否和你要安装应用的authority相同,如果相同则会弹出上述警告,并且安装失败。

解决方案

在定义provider是,使用软编码的形式,如下:

<provider    android:name="android.support.v4.content.FileProvider"    android:authorities="${applicationId}.fileprovider"    android:grantUriPermissions="true"    android:exported="false">    <meta-data        android:name="android.support.FILE_PROVIDER_PATHS"        android:resource="@xml/file_paths" /></provider>

上述代码中通过${applicationId}.fileprovider的形式来指定providerauthorities,所以该providerauthorities会根据applicationId的不同而不同,从而避免了authorities的冲突问题。

那么如何使用刚才定义的authorities呢?
我们在定义authorities是采用了applicationId+fileprovider的形式,在获取authorities的时候,我们就可以通过包名+fileprovider来获取,代码如下:

public final static String getFileProviderName(Context context){    return context.getPackageName()+".fileprovider";}

最后

既然来了,留下个喜欢再走吧,鼓励我继续创作(^_^)∠※

如果喜欢我的文章,那就关注我的博客吧,让我们一起做朋友~~

戳这里,加关注哦:

微博:第一时间获取推送
个人博客:干货文章都在这里哦
GitHub:我的开源项目

4 0
原创粉丝点击