【Android 开发教程】发送Email
2013-09-03 14:11
225 查看
本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/
类似SMS,Android系统同样支持通过编码的方式发送Email。
1. 新建一个工程,Emails。
2. 修改main.xml文件。
3. EmailsActivity.java中的代码。
这里,唯一要做的就是新建一个Intent对象,然后设置相应的参数。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/
类似SMS,Android系统同样支持通过编码的方式发送Email。
1. 新建一个工程,Emails。
2. 修改main.xml文件。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/btnSendEmail" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Send Email" android:onClick="onClick" /> </LinearLayout>
3. EmailsActivity.java中的代码。
public class EmailsActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onClick(View v) { String[] to = {"someguy@yourcompany.com", "anotherguy@yourcompany.com"}; String[] cc = {"busybody@yourcompany.com"}; sendEmail(to, cc, "Hello", "Hello my friends!"); } //?sends an SMS message to another device? private void sendEmail(String[] emailAddresses, String[] carbonCopies, String subject, String message) { Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setData(Uri.parse("mailto:")); String[] to = emailAddresses; String[] cc = carbonCopies; emailIntent.putExtra(Intent.EXTRA_EMAIL, to); emailIntent.putExtra(Intent.EXTRA_CC, cc); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(Intent.EXTRA_TEXT, message); emailIntent.setType("message/rfc822"); startActivity(Intent.createChooser(emailIntent, "Email")); } }4. 调试。
这里,唯一要做的就是新建一个Intent对象,然后设置相应的参数。
Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setData(Uri.parse("mailto:")); String[] to = emailAddresses; String[] cc = carbonCopies; emailIntent.putExtra(Intent.EXTRA_EMAIL, to); emailIntent.putExtra(Intent.EXTRA_CC, cc); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(Intent.EXTRA_TEXT, message); emailIntent.setType("message/rfc822"); startActivity(Intent.createChooser(emailIntent, "Email"));
相关文章推荐
- 【Android 开发教程】使用Intent发送短信
- Android开发中怎样调用系统Email发送邮件(多种调用方式)
- 【Android 开发教程】获取发送短信后的反馈
- Android开发中使用Volley库发送HTTP请求的实例教程
- Android开发中怎样调用系统Email发送邮件(多种调用方式)
- 在Android开发中怎样调用系统Email发送邮件
- 【Android 开发教程】通过编码实现发送短信
- Android开发中怎样调用系统Email发送邮件(多种调用方式)
- Android开发中怎样调用系统Email发送邮件(多种调用方式)
- android平台phonegap开发中使用EmailComposer插件发送邮件带附件失败的问题总结
- Android OpenGL ES 开发教程 从入门到精通
- [下载]Google Android开发精华教程
- 微信公众帐号开发教程第12篇-符号表情的发送(下)
- 【Android 开发教程】Spinner
- Android OpenGL ES 简明开发教程六: 真正的3D图形
- Android高手进阶教程(八)之----Android Widget开发案例(世界杯倒计时!)
- 【Android LibGDX游戏引擎开发教程】第07期:中文字体的显示和绘制(上)
- Android开发环境搭建教程
- Android应用开发笔记(1):调用打电话和发短信、收短信接口、发Email (Call, Dial, SMSManager, Broadcast, Email)