如何在android中向邮件发送pdf文件
我使用了下面的编码并将pdf发送至邮件。此pdf未附在邮件中。请给我任何解决方案如何在android中向邮件发送pdf文件,android,Android,我使用了下面的编码并将pdf发送至邮件。此pdf未附在邮件中。请给我任何解决方案 File PayslipDir = new File(Environment.getExternalStorageDirectory(), "/sample/"); // Write your file to that directory and capture the Uri String strFilename =string3; File htmlFile =
File PayslipDir = new File(Environment.getExternalStorageDirectory(), "/sample/");
// Write your file to that directory and capture the Uri
String strFilename =string3;
File htmlFile = new File(PayslipDir, strFilename);
// Save file encoded as html
Uri htmlUri = Uri.fromFile(htmlFile);
System.out.println("uri"+htmlUri);
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("application/pdf");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Pdf attachment");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Hi PDF is attached in this mail. ");
emailIntent.putExtra(Intent.EXTRA_STREAM, htmlUri);
PDFViewerActivity.this.startActivity(Intent.createChooser(emailIntent,"Send mail..."));
下面的代码对我来说很好:-
sPhotoFileName=Environment.getExternalStorageDirectory()+"/sankettest/siteriskassesment.png";
send.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"me@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"go on read the emails");
Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("file:///"+ sPhotoFileName));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/sanket test/siteriskassesment.png"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
希望这能奏效
emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/pdf");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/MyPdf.pdf"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
你需要改变
emailIntent.setType("application/pdf");
到
我希望这会有帮助 您遇到了什么错误?请使用java mail api执行此操作。请尝试此操作,无错误。但邮件中未附加pdf文件。
emailIntent.setType("text/html");