直接代码

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>


android调用系统邮件组件(intent匹配的流程)_第1张图片

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


更多相关文章

  1. Android 图片左上角、右上角标签tag
  2. Android 快速使用 string.xml 中的array标签
  3. 可循环显示图像的Android Gallery组件
  4. TabHost自定义标签页(一)
  5. android调用邮件应用发送email

随机推荐

  1. android lisetview的多列模版
  2. android倒计时(整理)
  3. 【Android】自带Theme
  4. Android点滴积累(一)
  5. Android layout布局属性、标签属性总结大
  6. Android(安卓)修改SeekBar样式,打造理想进
  7. [摘]android 入门xml布局文件
  8. ok6410 android driver(11)
  9. Android API中文文档GridView
  10. NestedScrollingParent, NestedScrolling