【发布时间】: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