Android 개발 중 시스템 이메일 발송 방법

Android에서 다른 프로그램을 호출하여 관련 처리를 하는 것은 거의 Intent를 사용하기 때문에 이메일도 예외가 아니다.Android에서 Email을 호출하는 데는 세 가지 유형의 Intent: Intent가 있습니다.ACTION_SENDTO 첨부 파일 없이 Intent 보내기.ACTION_SEND 첨부 파일 전송 Intent.ACTION_SEND_멀티 첨부 파일이 있는 MULTIPLE 발송은 물론 호출 이메일이라는 것은 이메일이 Intent를 수신하고 이런 일을 할 수 있다는 것일 뿐, 다른 응용 프로그램이 관련 기능을 실현했기 때문에 실행할 때 선택 상자가 나타날 수 있습니다.1. SENTTO를 사용하여 [java]를 보냅니다
 
Intent data=new Intent(Intent.ACTION_SENDTO);
data.setData(Uri.parse("mailto:[email protected]"));
data.putExtra(Intent.EXTRA_SUBJECT, " ");
data.putExtra(Intent.EXTRA_TEXT, " ");
startActivity(data);

Intent data=new Intent(Intent.ACTION_SENDTO);
data.setData(Uri.parse("mailto:[email protected]"));
data.putExtra(Intent.EXTRA_SUBJECT, " ");
data.putExtra(Intent.EXTRA_TEXT, " ");
startActivity(data);
Intent의putExtra에 메일에 대한 매개 변수를 설정합니다.2. SEND를 사용하여 [java]를 보냅니다
 
Intent intent = new Intent(Intent.ACTION_SEND);
String[] tos = { "[email protected]" };
String[] ccs = { "[email protected]" };
String[] bccs = {"[email protected]"};
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_BCC, bccs);
intent.putExtra(Intent.EXTRA_TEXT, "body");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");

intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/a.jpg"));
intent.setType("image/*");
intent.setType("message/rfc882");
Intent.createChooser(intent, "Choose Email Client");
startActivity(intent);

Intent intent = new Intent(Intent.ACTION_SEND);
String[] tos = { "[email protected]" };
String[] ccs = { "[email protected]" };
String[] bccs = {"[email protected]"};
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_BCC, bccs);
intent.putExtra(Intent.EXTRA_TEXT, "body");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");

intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/a.jpg"));
intent.setType("image/*");
intent.setType("message/rfc882");
Intent.createChooser(intent, "Choose Email Client");
startActivity(intent);
간단합니다. 우편물 발송에는 수령자, 사송자, 밀송자가 있습니다.즉, 각각 Intent를 통해EXTRA_EMAIL, Intent.EXTRA_CC, Intent.EXTRA_BCC는 putExtra로 설정하고 하나의 첨부 파일은 Intent로 보냅니다.EXTRA_STREAM에서 첨부 파일의 주소 Uri를 설정합니다.3. SEND_ 사용MULTIPLE에서 여러 첨부 파일을 보내기 위해 [java]
 
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
String[] tos = { "[email protected]" };
String[] ccs = { "[email protected]" };
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, "body");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");

ArrayList<uri> imageUris = new ArrayList<uri>();
imageUris.add(Uri.parse("file:///mnt/sdcard/a.jpg"));
imageUris.add(Uri.parse("file:///mnt/sdcard/b.jpg"));
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
intent.setType("image/*");
intent.setType("message/rfc882");
Intent.createChooser(intent, "Choose Email Client");
startActivity(intent);

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
String[] tos = { "[email protected]" };
String[] ccs = { "[email protected]" };
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, "body");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");

ArrayList<uri> imageUris = new ArrayList<uri>();
imageUris.add(Uri.parse("file:///mnt/sdcard/a.jpg"));
imageUris.add(Uri.parse("file:///mnt/sdcard/b.jpg"));
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
intent.setType("image/*");
intent.setType("message/rfc882");
Intent.createChooser(intent, "Choose Email Client");
startActivity(intent);
여러 개의 첨부 파일을 보내는데 가장 중요한 것은putParcelable Array ListExtra를 통해 여러 개의 첨부 파일의 Uri 주소 List를 설정하면 OK입니다.사실은 아주 간단해요.

좋은 웹페이지 즐겨찾기