可以访问外部存储文件并将其作为电子邮件附件发送

问题描述

我想发送带有pdf文件的电子邮件。当我尝试通过URI发送它们时,出现以下错误消息:

android.os.FileUriExposedException: file:///Download/myPDFFile.pdf exposed beyond app through ClipData.Item.getUri()

因此,我尝试使用fileprovider进行相同操作。在这里,我收到此错误消息:

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..."));

               

我已经尝试了几种方法来完成该电子邮件附件,但是我永远无法访问我的外部存储。有人知道如何解决吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...