android调用系统邮件组件(intent匹配的流程)
2014-03-04 10:09
405 查看
直接代码
demo地址:http://download.csdn.net/detail/pangzaifei/6989527
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; @Override protected 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() { @Override public 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); } @Override public 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
相关文章推荐
- Android 用Intent调用系统中经常被用到的组件
- Android调用系统组件常用uri & intent设置
- Android 用Intent调用系统中经常被用到的组件
- Android开发学习笔记:用Intent调用系统中经常被用到的组件
- Android 用Intent调用系统中经常被用到的组件
- Android开发——Intent调用系统组件21个常用小示例
- 用Intent调用Android系统中经常被用到的组件
- Android 用Intent调用系统中经常被用到的组件
- Android 用Intent调用系统中经常被用到的组件
- android intent调用隐式调用系统
- Android--通用intent(可直接调用的系统activity)
- Android调用系统邮件类应用的正确实现方法
- android组件通讯 Intent- 系统标准的Activity Action应用
- Android开发中怎样调用系统Email发送邮件(多种调用方式)
- Android中通过Intent 调用系统的图片、视频、音频、录音、拍照
- 使用intent调用Android系统自带应用
- android中使用Intent调用系统浏览器时要注意的.
- android调用系统短信Intent时将预填接收号码和内容
- android 系统Intent调用
- Android Intent调用大全、系统自带Intent调用大全