Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidMainfest - should an intent-filter have multiple actions?

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" />
like image 376
Bachalo Avatar asked Jan 22 '14 21:01

Bachalo


1 Answers

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.

like image 191
CommonsWare Avatar answered Oct 13 '22 00:10

CommonsWare