记录下intent相关学习

官方文档:https://developer.android.com/guide/components/intents-filters?hl=zh-cn

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属性,才能被其他应用打开。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值