直接代码

package com.example.demoemail;import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;/** * 调用邮件组件,主要是用到了intent的相关知识 * 1.首先需要在清单文件的Activity中配置action标签(动作,此处指明是调用系统的邮件组件android.intent.action.SENDTO) * 需要设置data标签,此处是对应的uri数据。 <data>的一般格式是scheme://host:post/path.具体代表含义请自己上网查询。 * 继续添加<catagory>标签,此标签是设置种类信息,像我们平常启动一个activity一般用startActivity(),如果调用了它,系统会默认的给Intent添加 <category android:name="android.intent.category.DEFAULT"/>, * 所以我们开发的时候不会出错。如果需要其他的种类,就必须要在清单文件中配置。否则会配皮失败,NO_MATCH_CATEGORY. * 2.在Activity中调用邮箱组件,使用Intent来设置action,data,category等。当你调用startActivity(),它会与清单文件你配置的<intent-filter>中信息配皮, * 如果匹配成功就调用邮件组件。 *  * 总结一下。intent组件的匹配流程。 * intent首先会与<intent-filter>的action相匹配,如果<action>为空,会匹配失败。NO_MATCH_ACTION.不继续进行 * 如果<intent-fileter>中<action>有,再判断intent.setAction()是否为空,如果不是空,就与<intent-fileter>中<action>相配皮,如果为空和前面匹配成功,就继续让Intent.setData和type与<intent-filter>中 * <data><type>相比较。如果匹配度>0则匹配成功(值越大,匹配越成功)。如果<0,则表示匹配失败。NO_MATCH_DATA.NO_MATCH_TYPE。最后比较<Category>信息。如果intent.setCategory与<Category>中信息有,匹配成功,否则 * 匹配失败。NO_MATCH_CATEGORY *  * 像之上NO_MATCH_CATEGORY这些返回的都是16进制的值,一般最高位为0表示成功。 * @author pangzf * */public class MainActivity extends Activity {private View vClick;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();setClickListener();}private void initView() {vClick = findViewById(R.id.tv_clcik);}private void setClickListener() {vClick.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {sendMail();};});}protected void sendMail() {Intent intent=new Intent();intent.setAction(Intent.ACTION_SENDTO);intent.setData(Uri.parse("mailto:pzfpang451@163.com"));startActivity(intent);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.demoemail"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="17" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.example.demoemail.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>             <intent-filter >                <action android:name="android.intent.action.SENDTO"/>                <data android:scheme="mailto"/>                <category android:name="android.intent.category.APP_BROWSER"/>                <category android:name="android.intent.category.DEFAULT"/>            </intent-filter>                    </activity>            </application></manifest>



demo地址:http://download.csdn.net/detail/pangzaifei/6989527


更多相关文章

  1. Android(安卓)完全掌握Service
  2. android中获取wifi信息
  3. Android调用Webview中的js方法
  4. Android(安卓)MIME类型与文件后缀名匹配部分
  5. Android(安卓)关机(reboot)流程
  6. Android(安卓)自定义文本框(带图片)
  7. android中调用系统的打电话功能
  8. Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片
  9. android点滴3

随机推荐

  1. Android(安卓)APK反编译详解(附图)
  2. Android培训HandlerThread的使用及源码解
  3. Android手动编译打包
  4. 实例:在Android调用WCF服务(wcf restful)
  5. 项目运行报错Error: Static interface me
  6. Android(安卓)调试桥
  7. Android(安卓)EditText光标颜色 与inputT
  8. Android中有关数据库SQLite的介绍
  9. 使用ViewFlipper来组织控件
  10. 在 ubuntu10.04下 载 android源码 步骤