ACTION_SENDTO สำหรับการส่งอีเมล

ฉันกำลังพบกับเงื่อนไขข้อผิดพลาด "การดำเนินการนี้ไม่ได้รับการสนับสนุนในปัจจุบัน" เมื่อรันโค้ดต่อไปนี้ใน Android 2.1 เกิดอะไรขึ้นกับตัวอย่างข้อมูล?

public void onClick(View v) {
  Intent intent = new Intent(Intent.ACTION_SENDTO);
  Uri uri = Uri.parse("mailto:[email protected]");
  intent.setData(uri);
  intent.putExtra("subject", "my subject");
  intent.putExtra("body", "my message");
  startActivity(intent);
}

person Sang Shin    schedule 28.06.2010    source แหล่งที่มา


คำตอบ (3)


หากคุณใช้ ACTION_SENDTO putExtra() จะไม่ทำงานเพื่อเพิ่มหัวเรื่องและข้อความใน Intent ใช้ setData() และเครื่องมือ Uri เพิ่มหัวเรื่องและข้อความ

ตัวอย่างนี้ใช้ได้กับฉัน:

// ACTION_SENDTO filters for email apps (discard bluetooth and others)
String uriText =
    "mailto:[email protected]" + 
    "?subject=" + Uri.encode("some subject text here") + 
    "&body=" + Uri.encode("some text here");

Uri uri = Uri.parse(uriText);

Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email")); 
person Pierangelo Dal Ben    schedule 02.04.2011
comment
คุณควรใช้ URLEncoder จริงๆ หรือไม่ นั่นจะไม่ทำให้ ' ' (เว้นวรรค) เป็น '+' และไม่ใช่ "%20" ใช่ไหม - person dacwe; 30.09.2012
comment
นี่เป็นสิ่งที่ฉันชอบ... แต่ฉันเพิ่งเจอสถานการณ์ที่โปรแกรมรับส่งเมลแทนที่เครื่องหมายบวกทั้งหมดด้วยอักขระเว้นวรรคตัวเดียว ดังนั้นตอนนี้ฉันจะออกจากเส้นทางนี้ ฉันคิดว่าแอปอีเมลทำการถอดรหัสบ่อยเกินไปหรือเช่นนั้น... พูดตรงๆ ฉันไม่อยากรู้... มันน่ารำคาญ - person class stacker; 29.01.2013
comment
...ดังนั้น ไม่ว่ายังไงก็ตาม E-Mail V3.0 จะเปลี่ยนเครื่องหมาย + ทั้งหมดให้เป็นช่องว่างหากคุณส่งผ่านเนื้อหาผ่าน URI ฉันไม่อยากจะเชื่อเลย - person class stacker; 29.01.2013
comment
Uri.parse(...) ดูเหมือนจะทำการเข้ารหัสให้กับคุณ ดังนั้นจริงๆ แล้ว URLEncoder ไม่จำเป็นเลย (หรือนั่นคือสิ่งที่ฉันพบ) นอกจากนี้ยังใช้งานได้กับ + - person Andrew Wyld; 10.12.2013

จริงๆ แล้ว ฉันพบวิธีการทำงานของ EXTRA แล้ว นี่คือการรวมกันของคำตอบที่ฉันพบที่นี่เกี่ยวกับ ACTION_SENDTO

http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when

และบางอย่างสำหรับ HTML ที่ฉันพบที่นี่:

วิธีส่งอีเมล HTML (แต่เป็นรูปแบบหนึ่งของวิธีใช้ ACTION_SENDTO ในโพสต์ HTML นี้ ไม่ได้ผลสำหรับฉัน - ฉันได้รับข้อความ "ไม่รองรับการดำเนินการ" ที่คุณเห็น)

    // works with blank mailId - user will have to fill in To: field
    String mailId="";
    // or can work with pre-filled-in To: field
// String mailId="[email protected]";
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, 
                                    Uri.fromParts("mailto",mailId, null)); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject text here"); 
    // you can use simple text like this
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Body text here"); 
    // or get fancy with HTML like this
emailIntent.putExtra(
             Intent.EXTRA_TEXT,
             Html.fromHtml(new StringBuilder()
                 .append("<p><b>Some Content</b></p>")
                 .append("<a>http://www.google.com</a>")
                 .append("<small><p>More content</p></small>")
                 .toString())
             );
startActivity(Intent.createChooser(emailIntent, "Send email..."));
person Andy Weinstein    schedule 09.11.2011
comment
ฉันได้เห็นวิธีแก้ปัญหานั้นแล้ว แต่มันไม่ใช่กรณีที่มันสร้างเมล HTML ที่เป็นไปตามมาตรฐาน ไคลเอนต์เมลจำนวนมากจะพยายามทำตัวฉลาดเป็นพิเศษและแสดงมันออกมา อย่างไรก็ตาม มีอีเมลที่ไม่เป็นไปตามมาตรฐานจำนวนมากถูกส่งทุกวันจนคุณไม่สามารถนับได้ นอกจากนี้ การรวมกันของ ACTION_SENDTO และ EXTRA_TEXT นี้ ไม่รองรับโปรแกรมรับส่งเมลทั้งหมด เช่น K-9 ก่อน 4.2 จะเพิกเฉยต่อความพิเศษ - person class stacker; 29.01.2013
comment
ยอดเยี่ยม ขอบคุณ ปรากฎว่านี่คือสิ่งที่ขัดขวางการส่ง HTML ให้ฉัน: emailIntent.setType("text/html"); ลบออกแล้วและใช้งานได้ดี - person Jonik; 18.01.2014

คุณสามารถลองสิ่งนี้ได้

 Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
            "mailto", emailID, null));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT,
            Subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT,
            Text);
    startActivity(Intent.createChooser(emailIntent, Choosertitle);

มันได้ผลสำหรับฉัน

person MPG    schedule 29.04.2015