是否可以在一个< intent-filter>中注册两个动作.活动 [英] Is it possible to register two actions within one <intent-filter> for Activity

查看:173
本文介绍了是否可以在一个< intent-filter>中注册两个动作.活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想注册我的启动器活动,因此可以通过单击图标并使用自定义方案打开链接来启动它.我设法使其正常工作,但我怀疑这是正确的方法.这是清单的相关部分:

I wanted to register my launcher activity so it could be started by both clicking on icon and opening link with a custom scheme. I managed to make it work but am questioning is this correct way. This is the relevant part of my manifest:

  <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="my.sheme" />
        </intent-filter>

这确实有效,但是我想知道我是否应该在相同的Intent过滤器下注册这两个动作.我尝试仅将标签从第二个过滤器移至第一个过滤器,但是安装后我的活动不显示图标.可以这样做吗?我只是犯了一些小语法错误(或破坏了声明规则的某些未记录顺序),或者我的想法完全错误,并且有更深层的原因导致此方法不起作用?

This does work but I was wondering should I register both actions under same intent filter. I tried just moving tags from second filter to the first one but then my activity doesn't show icon on install. Is it possible to do it this way and I just made some small syntax error(or broke some undocumented order of declaration rule) or is my thinking completely wrong on this and there are deeper reasons why this doesn't work?

注意:我确实设置了android:exported ="true",但android.intent.action.MAIN即使没有它也可以工作,因为如果您使用action.MAIN,它仍然会被导出

NOTE:I do set android:exported="true"but android.intent.action.MAIN works even without it because it becomes exported anyway if you use action.MAIN

推荐答案

作为

当您要处理多种类型的意图时,但仅以动作,数据和类别类型的特定组合处理时,则需要创建多个意图过滤器.

When you want to handle multiple kinds of intents, but only in specific combinations of action, data, and category type, then you need to create multiple intent filters.

否则,您可以将它们分组到一个意图过滤器中.

Otherwise you can group them into one intent-filter.

这篇关于是否可以在一个&lt; intent-filter&gt;中注册两个动作.活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆