在Android应用程序中添加多个文件提供程序 [英] Adding multiple file providers in Android application

查看:118
本文介绍了在Android应用程序中添加多个文件提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我正在开发需要外部应用程序依赖项(.aar文件)的android应用程序 库应用程序具有其自己的文件提供程序,而我的应用程序也具有其自己的文件.

guys, I am working on an android application for which I need external application dependency(.aar file) library application has its own file provider and my application have its own.

库运行良好,但是当我将其包含在应用程序中时,相机功能将无法正常运行.我收到以下错误

library work well when I run it as a separate app but when I include it my application then camera functionality not working. I get the following error

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

遵循应用程序的清单文件

following the manifest file of the application

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

以下是lib模块的清单文件

and the following is a manifest file of the lib module

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.ma.bot.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

应用程序和lib模块都有不同的程序包名称,如何将这2个文件提供程序添加到应用程序中 我也尝试使用多个文件提供程序,但是在应用程序编译时出现XML解析错误.

both application and lib module have different package name how I add this 2 file providers into the application I also try including multiple file providers using, but I get XML parse error on app compilation.

android:authorities="${applicationId}.provider;com.ma.bot.provider"

如何解决这个问题.

推荐答案

我在此链接上找到了解决方案 可以在FileProvider中使用多个权限吗?

Guys I found solution on this link Possible to use multiple authorities with FileProvider?

基本上的问题是我的库和应用程序具有相同的名称android.support.v4.content.FileProvider,因此它在清单合并中发生冲突,为避免这种情况,我需要删除扩展文件提供程序的空类并使用它的提供程序名称

Basically problem is my library and application have same name android.support.v4.content.FileProvider so it colliding in manifest merger, to avoid this I need to defile empty class extending File provider and use it provider name

<provider
            android:name="com.MAG.MAGFileProvider"
            android:authorities="${applicationId}.provider;"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

并声明这样的类

import android.support.v4.content.FileProvider;
public class MAGFileProvider extends FileProvider
{
    //we extend fileprovider to stop collision with chatbot library file provider
    //this class is empty and used in manifest
}

这篇关于在Android应用程序中添加多个文件提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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