Android
定义一个可被其他程序调用的activity,就像android中的联系人列表、打电话功能等。
1、AndroidManifest.xml文件中,在你想提供的activity里,添加一个intent-filter。如下:
<intent-filter>
<action android:name="com.xingjiu.acttest"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme ="coor"/>
</intent-filter>
2、各配置解释:
action,指明对外名字。如本例中的名字为“com.xingjiu.acttest”,调用本activity的语句就可能为:Intent intent = new Intent("com.xingjiu.acttest");
startActivity(intent);
category,直接default就好。
data,指明传递给该activity的数据格式。每个<data>元素指定一个URI和数据类型(MIME类型)。它有四个属性scheme、host、port、path对应于URI的每个部分:
scheme://host:port/path
这四个属性都是可选的,但它们之间并不都是完全独立的。要让authority有意义,scheme必须也要指定。要让path有意义,scheme和authority也都必须要指定。
例如,下面的URI:content://com.example.project:200/folder/subfolder/etc
scheme是content,host是"com.example.project",port是200,path是"folder/subfolder/etc"。host和port一起构成URI的凭据(authority),如果host没有指定,port也被忽略。
3、当比较intent对象和过滤器的URI时,仅仅比较过滤器中出现的URI属性。例如,如果一个过滤器仅指定了scheme,所有有此scheme的URIs都匹配过滤器;如果一个过滤器指定了scheme和authority,但没有指定path,所有匹配scheme和authority的URIs都通过检测,而不管它们的path;如果四个属性都指定了,要都匹配才能算是匹配。然而,过滤器中的path可以包含通配符来要求匹配path中的一部分。
更多相关文章
- TextView属性总结
- android 创建 删除桌面快捷方式
- Android中如何一次性finish掉以前打开的所有的activity
- Android获取本机局域网IP的方法
- android:autoLink
- 在服务器上使用grandle打包android源码
- [Android设计模式]Android退出应用程序终极方法
- android 9.0 开机连接指定wifi
- Android(安卓)发送通知