Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

android - How to send email with Attachment(Image)

I am tryed two ways to send email with image attachment.The attachment is displaying at the time of writing subject,boby everything aftersend that email at the receiver it's showing only subject & Body only no attacthment the user getting.I am not understanding what's worong with my code below is my code. please give my Any suggestion to finish this task.

Type 1:-

   Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
   picMessageIntent.setType("image/jpeg");
   File downloadedPic = new File(Environment.getExternalStorageDirectory(), strFileName + ".jpg");// Art_Nature
   picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));//screenshotUri );//Uri.fromFile(new File("downloadedPic"))); //Uri.fromFile(downloadedPic)); // Uri.fromFile(new File("/path/to/downloadedPic")));
        startActivity(Intent.createChooser(picMessageIntent, "Share image using"));

Type 2:

 ArrayList<Uri> uris = new ArrayList<Uri>();   
 Uri u;        
 Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
 picMessageIntent.setType("image/jpeg");
 File downloadedPic = new File(Environment.getExternalStorageDirectory(), strFileName + ".jpg");// Art_Nature           
 if(downloadedPic.exists())
    {
      Uri u1 = Uri.fromFile(downloadedPic);
      uris.add(u1);
      picMessageIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
      startActivity(picMessageIntent);
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is something that can help you. Make sure you spelled your image file path in a proper manner. Don't forget the "/" separator (try to get a log of your path). Also, be sure that the file exists.

/** ATTACHING IMAGE TO EMAIL AND SENDING EMAIL  */
        Button b1 = (Button)findViewById(R.id.finalsectionsubmit);
        b1.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
//        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailSignature);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, toSenders);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subjectText);
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, messageText+"

"+emailSignature); 

        emailIntent.setType("image/jpeg");
        File bitmapFile = new File(Environment.getExternalStorageDirectory()+
            "/"+FOLDER_NAME+"/picture.jpg");
        myUri = Uri.fromFile(bitmapFile);
        emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);


        startActivity(Intent.createChooser(emailIntent, "Send your email in:"));
        eraseContent();
        sentMode = true;
      }
    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...