很好的一天!我在通过电子邮件发送文件时遇到了问题(我使用fileprovider)下面的代码一切只在我取消注解emailintent.puttera(android.content.intent.extra\u stream,uri)行时工作,没有崩溃发送表单出现,但没有发送到给定的地址可能我遗漏了什么,请帮助。
File file = new File(MainActivity.this.getCacheDir(), "test.txt");
if (file.exists() == false);
file.mkdirs();
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(MainActivity.this.openFileOutput("test.txt", Context.MODE_PRIVATE));
for(int i=0;i<values.size();i++)
outputStreamWriter.write(values.get(i)+"\n");
outputStreamWriter.close();
}
catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
Uri uri = FileProvider.getUriForFile(MainActivity.this,AUTHORITY,file);
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "test@gmail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_CC, new String[] {});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "FROM Sample");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "HI");
// emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
MainActivity.this.startActivity(emailIntent);
文件提供者
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="app.testapp"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
提供程序路径:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="my_images"
path="images/" />
<files-path
name="my_docs"
path="docs/" />
<external-files-path
name="external_files_dir"
path="/" />
<cache-path
name="cache"
path="/" />
<external-cache-path
name="external_cache_dir"
path="/" />
<external-media-path
name="external_media_dir"
path="/" />
<external-media-path
name="external_media_dir"
path="/" />
暂无答案!
目前还没有任何答案,快来回答吧!