美文网首页
7.0 Provider问题

7.0 Provider问题

作者: ae12 | 来源:发表于2017-11-01 15:56 被阅读23次

    Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
    解决方案:AndroidManifest.xml处的android:authorities必须跟mActivity.getPackageName() + ".fileprovider"一样
    2.Manifest 中的Provider声明:
    <provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/provider_paths"/>
    </provider>
    里面的xml文件:xml/provider_paths ,配置注意:
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path path="Android/data/com/pgyersdk" name="files_root" />
    <external-path path="." name="external_storage_root" />
    <external-path path="knowledge_files" name="knowledge" /></paths>

    在你引用的时候如下:
    file 的文件路径里一定要 有XML文件里声明的其中一个(如:有一个knowledge/)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    Log.e("----", "getPdfFileIntent: "+file.getPath() );
    fileUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", file);
    } else {
    fileUri = Uri.fromFile(file);
    }

    相关文章

      网友评论

          本文标题:7.0 Provider问题

          本文链接:https://www.haomeiwen.com/subject/ayrgpxtx.html