Android email intent
来源:互联网 发布:智器PDF阅读软件 编辑:程序博客网 时间:2024/05/17 06:37
Intent i = new Intent(Intent.ACTION_SEND); //i.setType("text/plain"); //use this line for testing in the emulator i.setType("message/rfc822") ; // use from live devicei.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@gmail.com"}); i.putExtra(Intent.EXTRA_SUBJECT,"subject goes here"); i.putExtra(Intent.EXTRA_TEXT,"body goes here"); startActivity(Intent.createChooser(i, "Select email application."));
public class MainActivity extends Activity {private EditText recipient;private EditText subject;private EditText body; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recipient = (EditText) findViewById(R.id.recipient); subject = (EditText) findViewById(R.id.subject); body = (EditText) findViewById(R.id.body); Button sendBtn = (Button) findViewById(R.id.sendEmail); sendBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { sendEmail(); // after sending the email, clear the fields recipient.setText(""); subject.setText(""); body.setText(""); } }); } protected void sendEmail() { String[] recipients = {recipient.getText().toString()}; Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); // prompts email clients only email.setType("message/rfc822"); email.putExtra(Intent.EXTRA_EMAIL, recipients); email.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString()); email.putExtra(Intent.EXTRA_TEXT, body.getText().toString()); try { // the user can choose the email client startActivity(Intent.createChooser(email, "Choose an email client from...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MainActivity.this, "No email client installed.", Toast.LENGTH_LONG).show(); } } }
public static Intent createEmailIntent(final String toEmail, final String subject, final String message){ Intent sendTo = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode(toEmail) + "?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(message); Uri uri = Uri.parse(uriText); sendTo.setData(uri); List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(sendTo, 0); // Emulators may not like this check... if (!resolveInfos.isEmpty()) { return sendTo; } // Nothing resolves send to, so fallback to send... Intent send = new Intent(Intent.ACTION_SEND); send.setType("text/plain"); send.putExtra(Intent.EXTRA_EMAIL, new String[] { toEmail }); send.putExtra(Intent.EXTRA_SUBJECT, subject); send.putExtra(Intent.EXTRA_TEXT, message); return Intent.createChooser(send, "Your Title Here");}
0 0
- Android email intent
- Android 使用 Intent 发送 email
- android后台发送Email(不借助Intent)
- android—Intent发送文本email
- 【email】android邮件Email
- Android:unable to start service Intent {act = com.android.email.ACCOUNT_INTENT}
- 启动Android程序:unable to start service Intent {act = com.android.email.ACCOUNT_INTENT}
- android email
- 第75章、再识Intent-调用发送Email程序(从零开始学Android)
- Android intent intent-filter
- Android intent intent-filter
- Android intent intent-filter
- Android intent
- Android Intent
- Android Intent
- android Intent
- android intent
- android intent
- 再谈UEFI下的Protocol概念
- 思维启发之浮点数
- AtomicInteger简介
- XP系统日志满处理方法
- plupload
- Android email intent
- 字符串相关函数使用之二
- tomcat 下webapps root 404问题
- ServletContext使用经验汇总
- 关于myeclipse 报Package Explorer”非正常显示的问题
- SVN操作详解
- 日常生活规划
- 基于HTML5/Javascrip的游戏开发框架Phaser
- selenium webdriver学习:如何操作select下拉框