【问题标题】:virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData虚拟方法'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData
【发布时间】:2018-11-03 04:32:39
【问题描述】:

阅读前请不要将其标记为重复

我已经搜索了 stackoverflow 和 Github 上的所有链接以寻找可能的答案,但仍然遇到同样的错误。

这是清单文件:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <provider android:authorities="com.example.aditya.pdf_report"
        android:exported="false" android:grantUriPermissions="true"
        android:name="android.support.v4.content.FileProvider"
        android:readPermission="com.company.aditya.pdf_report.READ">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"/>
    </provider>
</application>

这里是 Java 文件:

    File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/pdf_report/" + reportname.getText().toString().trim() + ".pdf" );
        Uri path;
        path = FileProvider.getUriForFile(MainActivity.this, getPackageName(),filelocation);
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
        emailIntent .setType("vnd.android.cursor.dir/email");

        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        emailIntent .putExtra(Intent.EXTRA_STREAM, path);
// the mail subject
        emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Here is the Branch Visit Report - Human Resources");
        startActivity(Intent.createChooser(emailIntent , "Send email..."));

这里是文件路径.xml:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="pdf_report" path="pdf_report/"/>
</paths>

这是我的包名:

com.example.aditya.pdf_report

这是我手机上保存 Pdf 的位置:

Environment.getExternalStorageDirectory().getAbsolutePath() + "/pdf_report"

我已经关注了所有链接,但我认为它是 file-paths.xml 我写错东西的地方

【问题讨论】:

  • 清单中的fileprovider 是什么?
  • 那是一个错字。那应该是我的应用程序的名称。但现在我收到此错误 Failed to find configured root that contains /storage/emulated/0/pdf_report/whfnscs.pdf
  • “请不要在阅读之前将其标记为重复”没有人这样做!

标签: android android-intent android-manifest android-fileprovider


【解决方案1】:

如下更改您的file-path.xml。这可能是工作。

<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
    name="external_files"
    path="." />
</paths>

【讨论】:

  • 非常感谢。有效。但我有一个问题,我们实际上如何写这个?因为没有一个答案从未提到实际写什么。
  • 所有细节都有很好的解释here.
  • 如果问题得到解决,您可以标记接受并投赞成票。因为它也可能对其他人有所帮助。
猜你喜欢
  • 2018-01-19
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-23
  • 2013-05-01
  • 1970-01-01
  • 2011-09-30
相关资源
最近更新 更多