我想发送一封附有 pdf 文件的电子邮件。当我尝试通过 URI 发送它们时,我收到以下错误消息:
android.os.FileUriExposedException: file:///Download/myPDFFile.pdf exposed beyond app through ClipData.Item.getUri()
所以我尝试对文件提供者做同样的事情。在这里,我收到此错误消息:
java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.example.digitalpaper.provider
String filename="myPDFFile.pdf";
File testFile = new File(Environment.DIRECTORY_DOWNLOADS, filename);
Uri path = FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()),BuildConfig.APPLICATION_ID + ".provider", testFile);
//----------------Sending the Mail----------------//
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/pdf");
String to[] = {"xyz@gmx.de",eT_email.getText().toString()};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Subject");
//-----------------------Attaching the file---------------------------------//
emailIntent.putExtra(Intent.EXTRA_STREAM, path);
// emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse( "file://"+filelocation));
startActivity(Intent.createChooser(emailIntent,"Send email..."));
我已经尝试了几种方法来完成该电子邮件附件,但我永远无法访问我的外部存储。有人知道如何解决吗?