티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Send Email Intent
이메일 전송 인텐트
문제 내용
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
startActivity(Intent.createChooser(intent, "Send Email"));
The above code opens a dialog showing the following apps:- Bluetooth, Google Docs, Yahoo Mail, Gmail, Orkut, Skype, etc.
위의 코드는 블루투스, 구글 독스, 야후 메일, 지메일, 오쿠트, 스카이프 등의 앱을 보여주는 대화상자를 엽니다.
Actually, I want to filter these list options. I want to show only email-related apps e.g. Gmail, and Yahoo Mail. How to do it?
실제로 이 목록 옵션을 필터링하고 싶습니다. 예를 들어 이메일 관련 앱만 표시합니다. Gmail, 그리고 Yahoo Mail. 어떻게 하나요?
I've seen such an example on the 'Android Market application.
나는 '안드로이드 마켓' 애플리케이션에서 그러한 예를 본 적이 있다.
- Open the Android Market app
- Open any application where the developer has specified his/her email address. (If you can't find such an app just open my app:- market://details?id=com.becomputer06.vehicle.diary.free, OR search by 'Vehicle Diary')
- Scroll down to 'DEVELOPER'
- Click on 'Send Email'
1. Android Market 앱 열기
2. 개발자가 자신의 이메일 주소를 지정한 응용 프로그램을 엽니다. (해당 응용 프로그램을 찾을 수 없으면 내 응용 프로그램을 여십시오:-market://market?id=com.computer06.vehicle.diary.free가 되거나 '차량 일지'로 검색하십시오.)
3. 아래로 스크롤하여 '개발자'로 이동합니다.
4. 'Send Email' 클릭
The dialog shows only email Apps e.g. Gmail, Yahoo Mail, etc. It does not show Bluetooth, Orkut, etc. What code produces such dialog?
대화 상자에는 e-메일 앱만 표시됩니다. 지메일, 야후메일 등 블루투스, 오쿠트 등을 보여주지 않는다. 어떤 코드가 이러한 대화상자를 생성합니까?
높은 점수를 받은 Solution
UPDATE
갱신하다
Official approach:
공식적인 접근 방식:
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
참조 링크
OLD ANSWER
오래된 답
The accepted answer doesn't work on the 4.1.2. This should work on all platforms:
4.1.2에서는 허용된 답변이 작동하지 않습니다. 이 기능은 모든 플랫폼에서 작동해야 합니다.
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
Update: According to marcwjj, it seems that on 4.3, we need to pass string array instead of a string for email address to make it work. We might need to add one more line:
업데이트: marcwjj에 따르면 4.3에서는 이메일 주소의 문자열 대신 문자열 배열을 전달해야 작동할 수 있는 것 같습니다. 다음 줄을 하나 더 추가해야 할 수도 있습니다.
intent.putExtra(Intent.EXTRA_EMAIL, addresses); // String[] addresses
가장 최근 달린 Solution
in Kotlin if anyone is looking
누군가 찾고 있다면 코틀린에서 아래와 같이 하세요.
val emailArrray:Array<String> = arrayOf("travelagentsupport@kkk.com")
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:") // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, emailArrray)
intent.putExtra(Intent.EXTRA_SUBJECT, "Inquire about travel agent")
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
출처 : https://stackoverflow.com/questions/8701634/send-email-intent
'개발 > 안드로이드' 카테고리의 다른 글
RecyclerView에서 아이템 사이에 디바이더 및 여백 추가하기 (0) | 2022.12.04 |
---|---|
화면 회전 시 액티비티 재시작 방지하기 (0) | 2022.12.03 |
안드로이드 앱에서 chooser 대신 Google Play Store 바로 열기 (0) | 2022.12.03 |
HTML 파일 WebView에 로드하기 (0) | 2022.12.03 |
부팅 시 서비스를 시작하기 (0) | 2022.12.02 |