How to send email with Attachment(Image)

馋奶兔 提交于 2019-12-29 02:08:13

问题


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);
    }

回答1:


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+"\n\n"+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;
      }
    });


来源:https://stackoverflow.com/questions/9860156/how-to-send-email-with-attachmentimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!