android添加附件到gmail应用程序

android添加附件到gmail应用程序

本文介绍了通过intent android添加附件到gmail应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序可以通过点击app,openwith和电子邮件附件来打开PDF。我将该文件转换为inputstream,然后转换为bytearray。现在我希望这个打开的pdf作为附件附加到使用Intent的gmail。我使用以下代码实现了这一点,该代码将pdf添加为没有大小的附件,但收到的邮件不包含附件,并且显示通知无法发送附件。试过很多方法..但不成功..最早的任何帮助。提前谢谢。



意图sendIntent = 意图(意图。 ACTION_VIEW); 
sendIntent.setType( application / pdf);
sendIntent.setData(Uri.parse( [email protected]));
sendIntent.setClassName( com.google.android.gm com.google.android.gm.ComposeActivityGmail);
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String [] { [email protected]});
sendIntent.putExtra(Intent.EXTRA_SUBJECT, testPDF);
sendIntent.putExtra(Intent.EXTRA_TEXT, 这是一个PDF);

文件pdfFile = null;
尝试 {
pdfFile = new 文件(attachmentFileName);
FileOutputStream fos = new FileOutputStream(pdfFile);
fos.write(bytes);
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}

Uri fileuri = Uri.fromFile(pdfFile);
sendIntent.putExtra(Intent.EXTRA_STREAM,fileuri);
// 启动gmailapp意图
startActivity(sendIntent);





我的尝试:



我试过使用我已经可用的inputstream和bytearray来生成uri和attach。我不想将文件物理地写入SD卡。 Avaialble inputstream或bytearray应转换为pdf并附加到gmail。

解决方案

I have an application which can open PDF via taping on app, openwith and also email attachment. I convert that file into inputstream and then to bytearray. Now I want this opened pdf to attach as attachment to gmail using Intent. I achieved this with the following code which adds pdf as attachment with no size, but received mail do not contain the attachment and a notification couldn't send attachment is displayed. Tried many ways.. but unsuccessful.. any help at the earliest. thanks in advance.

Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                sendIntent.setType("application/pdf");
                sendIntent.setData(Uri.parse("[email protected]"));
                sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
                sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
                sendIntent.putExtra(Intent.EXTRA_SUBJECT, "testPDF");
                sendIntent.putExtra(Intent.EXTRA_TEXT, "this is a PDF ");

                File pdfFile=null;
            try {
                pdfFile = new File(attachmentFileName);
                FileOutputStream fos = new FileOutputStream(pdfFile);
                fos.write(bytes);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

                Uri fileuri = Uri.fromFile(pdfFile);
                 sendIntent.putExtra(Intent.EXTRA_STREAM, fileuri);
                //start the gmailapp intent
                startActivity(sendIntent);



What I have tried:

I tried to use inputstream and bytearray already available with me to generate uri and attach. I dont want to physically write the file into SD card. Avaialble inputstream or bytearray should be converted to pdf and attach to gmail.

解决方案


这篇关于通过intent android添加附件到gmail应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 00:37