IT_Programming/Android_Java

Android 이메일&MMS 로 이미지 파일 첨부 보내기

JJun ™ 2015. 6. 24. 07:42

 


 출처: http://mashroom.tistory.com/17


 

* Case Email
-

private void SendEmail(String subject, String text, ArrayList<String>filePaths, String... addressTo)

{

          Intent sendIntent = new Intent(Intent.ACTION_SEND);

          sendIntent.setType("image/jpeg");

          sendIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");

          sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filePaths.get(0)));

          sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the photo");

          startActivity(Intent.createChooser(sendIntent, "Email:"));

}

 



* Case MMS
-

private void SendMMS(Context context, ArrayList<String> urlString)

{

          boolean exceptionCheck = false;

          Intent sendIntent = new Intent();

 // Selection count

          if (urlString.size() > 1) {

                    sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
          } else if (urlString.size() == 1) {

                    sendIntent.setAction(Intent.ACTION_SEND);

          } else {

                    Toast.makeText(this, "Please Check the Image.", Toast.LENGTH_LONG).show();

                    exceptionCheck = true;

          }

          if (!exceptionCheck) {

                    sendIntent.setData(Uri.parse("mmsto:"));

                    sendIntent.addCategory("android.intent.category.DEFAULT");

                   

                    ArrayList<Uri> uris = new ArrayList<Uri>();

                    for (String file : urlString) {

                              File fileIn = new File("file://" + file);

                              Uri u = Uri.fromFile(fileIn);

                              uris.add(u);

                    }

                    sendIntent.setType("image/jpeg");

                    if (urlString.size() > 1) {

                              sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

                    } else {

                              sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + urlString.get(0)));

                    }

          }

 

          try

          {

                    startActivity(sendIntent);

          } catch (Exception e) {

                    Toast.makeText(this, "Send Failed..", Toast.LENGTH_LONG).show();

          }
     }