如何将pdf文件发送到android中的邮件

时间:2014-05-15 12:18:06

标签: android

我使用了以下编码并将pdf发送到mail.This pdf没有附在mail.pls给我任何解决方案。

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

3 个答案:

答案 0 :(得分:0)

下面的代码对我来说很好: -

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

        }
    });

答案 1 :(得分:0)

希望这有效

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

答案 2 :(得分:0)

您需要更改

emailIntent.setType("application/pdf");

emailIntent.setType("text/html");

我希望它会有所帮助!!