1、如何通过uri打开某个应用?
打开应用的代码,需要给Intent设置action,data,category等内容;
被打开的应用,需要在AndroidManifest.xml中给组件设置intent-filter,intent-filter中的内容和打开应用的Intent中的内容对上,就能被打开。
2、action,data,category都是做什么用的?
action指组件要处理的操作类型,view表示展示内容,send表示接收数据等。
data是指发送的数据,一般可以指定类型,例如分享功能,或者指定uri。
category指Intent类别,例如Browsable表示允许从网络浏览器打开,Launcher表示启动页面等。
3、Uri是什么?
Uri是指统一资源标识符,一般格式如下:
[协议名]://[用户名]:[密码]@[主机名]:[端口]/[路径]?[查询参数]#[片段ID]
hierarchical part ┌───────────────────┴─────────────────────┐ authority path ┌───────────────┴───────────────┐┌───┴────┐ abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1 └┬┘ └───────┬───────┘ └────┬────┘ └┬┘ └─────────┬─────────┘ └──┬──┘ scheme user information host port query fragment urn:example:mammal:monotreme:echidna └┬┘ └──────────────┬───────────────┘ scheme path
Intent-filter中可以指定这些内容:
<intent-filter> <action android:name="android.intent.action.SEND"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="http://"/> <data android:host="zulong.com"/> <data android:path="/res/login"/> </intent-filter>
4、带Intent-filter的组件,必须添加exported:true属性,才能被其他应用打开。