AndroidMainfest - 应该意图过滤器有多个动作? [英] AndroidMainfest - should an intent-filter have multiple actions?

查看:137
本文介绍了AndroidMainfest - 应该意图过滤器有多个动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在的意向过滤器对我的MainActivity看起来像这样

 <意向滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>
                <类机器人:名字=android.intent.category.LAUNCHER/>
                <作用机器人:名字=android.hardware.usb.action.USB_ACCESSORY_ATTACHED/>
            &所述; /意图滤光器>

请注意,有2个动作节点。它是否正确?还是说只是每意图过滤器一个动作节点?

此外,什么是默认类别的目的是什么?

 <类机器人:名字=android.intent.category.DEFAULT/>


解决方案

  

这是正确的?


它可以是,尽管在这种情况下,我怀疑这是不是你想要的。

<意向滤光器> 将匹配:


  • 意图动作和 LAUNCHER 类别,或


  • 意图 USB_ACCESSORY_ATTACHED LAUNCHER 类别


前者是常见的。不过,我倒是怀疑 USB_ACCESSORY_ATTACHED 将与 LAUNCHER 类使用。我甚至不能确定它是用来用的活动的,因为文档有点糊涂这一点。

My current intent-filter for my MainActivity looks like this

<intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
            </intent-filter>

Notice that there are 2 action nodes. Is this correct? Or should there only be one action node per intent-filter?

Also, what is the purpose of the DEFAULT category?

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

解决方案

Is this correct?

It can be, though in this case I suspect it is not what you want.

This <intent-filter> will match:

  • an Intent with the MAIN action and the LAUNCHER category, or

  • an Intent with the USB_ACCESSORY_ATTACHED and the LAUNCHER category

The former is common. However, I rather doubt that USB_ACCESSORY_ATTACHED will be used with the LAUNCHER category. I am not even sure it is used with activities, as the documentation is a bit muddled on this point.

这篇关于AndroidMainfest - 应该意图过滤器有多个动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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