Android 系列 4.2从视图发送电子邮件文本
来源:互联网 发布:电话轰炸机淘宝叫什么 编辑:程序博客网 时间:2024/05/29 19:46
4.2从视图发送电子邮件文本
问题
您想要从视图发送包含文本或图像的电子邮件。
解
将要通过电子邮件发送到邮件应用程序的数据作为参数传递给intent。
讨论
从视图发送电子邮件文本的步骤非常简单:
1.修改AndroidManifest.xml文件以允许Internet连接,以便可以发送电子邮件。 这在实施例4-1中示出。
2.使用用户单击的电子邮件按钮创建视觉表示层。 布局如例4-2所示,用于填充它的字符串如例4-3所示。
3.附加OnClickListener以允许在用户单击电子邮件按钮时发送电子邮件。 代码如例4-4所示。
问题
您想要从视图发送包含文本或图像的电子邮件。
解
将要通过电子邮件发送到邮件应用程序的数据作为参数传递给intent。
讨论
从视图发送电子邮件文本的步骤非常简单:
1.修改AndroidManifest.xml文件以允许Internet连接,以便可以发送电子邮件。 这在实施例4-1中示出。
2.使用用户单击的电子邮件按钮创建视觉表示层。 布局如例4-2所示,用于填充它的字符串如例4-3所示。
3.附加OnClickListener以允许在用户单击电子邮件按钮时发送电子邮件。 代码如例4-4所示。
实例4-1。 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.examples"android:versionCode="1"android:versionName="1.0"><uses-permissionandroid:name="android.permission.INTERNET" /><applicationandroid:icon="@drawable/icon"android:label="@string/app_name"><activityandroid:name=".Main"android:label="@string/app_name"><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>
实例4-2。 Main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><Buttonandroid:id="@+id/emailButton"android:text="Email Text!"android:layout_width="fill_parent"android:layout_height="wrap_content"></Button><TextViewandroid:id="@+id/text_to_email"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/my_text" /></LinearLayout>
实例4-3。Strings.xml
<?xml version="1.0" encoding="utf-8"?><resources><stringname="hello">Hello World, Main!</string><stringname="app_name">EmailFromView</string><stringname="my_text">Lorem Ipsum is simply dummy text of the printing and typesetting industry. LoremIpsum has been the industry's standard dummy text ever since the 1500s, whenan unknown printer took a galley of type and scrambled it to make a typespecimen book. It has survived not only five centuries, but also the leap intoelectronic typesetting, remaining essentially unchanged. It was popularised inthe 1960s with the release of Letraset sheets containing Lorem Ipsum passages,and more recently with desktop publishing software like Aldus PageMakerincluding versions of Lorem Ipsum.</string></resources>
实例4-4。 Main.java
import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class Main extends Activity implements OnClickListener {private static final String TAG = "Main";private Button emailButton;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// Set the View LayersetContentView(R.layout.main);// Get reference to Email Buttonthis.emailButton = (Button) this.findViewById(R.id.emailButton);// Sets the Event Listener onClickthis.emailButton.setOnClickListener(this);}@Overridepublic void onClick(View view) {if (view == this.emailButton) {Intent emailIntent = new Intent(Intent.ACTION_SEND);emailIntent.setType("text/html");emailIntent.putExtra(Intent.EXTRA_TITLE, "My Title");emailIntent.putExtra(Intent.EXTRA_SUBJECT, "My Subject");// Obtain reference to String and pass it to IntentemailIntent.putExtra(Intent.EXTRA_TEXT,getString(R.string.my_text));startActivity(emailIntent);}}}
0 0
- Android 系列 4.2从视图发送电子邮件文本
- Android 系列 4.3使用附件发送电子邮件
- Android 发送电子邮件范例
- 从指定邮箱发送电子邮件
- 从Oracle9i中发送电子邮件
- 从asp.net页面发送电子邮件
- 从asp.net页面发送电子邮件
- C# 发送纯文本的电子邮件(e-mail)
- 发送电子邮件
- 发送电子邮件
- 发送电子邮件
- 发送电子邮件
- 发送电子邮件
- 发送电子邮件
- 发送电子邮件
- 电子邮件发送
- 发送电子邮件
- 发送电子邮件
- java decimalFormat 的用法
- 关于Carthage添加的框架image not found问题
- 架构师知识体系(5)--建立自己的知识体系吧
- mysql的一些常用功能记录
- Android - 多Fragment ,toolbar 菜单错乱问题
- Android 系列 4.2从视图发送电子邮件文本
- Hololens官方教程精简版 - 04. Gesture(手势)
- 《喵神-王巍博客》读书笔记,开发篇(4)
- 【安卓开发】Facebook工程师是如何改进他们Android客户端的
- 根据wsdl调用webservice接口
- ION-DTN RC配置文件分析
- SSH商城Demo --- 四、数据库表设计
- maven入门(1)
- Linux学习之CentOS--CentOS6.5下Mysql数据库的安装与配置