Is it possible to register two actions within one

2019-04-21 05:24发布

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>

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?

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

1条回答
一纸荒年 Trace。
2楼-- · 2019-04-21 05:50

As the Android documentation states:

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.

查看更多
登录 后发表回答