intent-filter with android:priority setting

2020-06-22 04:06发布

问题:

I test the intent-filter android:priority="0" and intent-filter android:priority="20" by android.intent.category.HOME. I list the information below,

    <activity android:name=".TestHomeActivity"
              android:label="@string/app_name">
        <intent-filter android:priority="0">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

When finishing system booting, it always pops up a dialog (ResolveActiivty) for choose preferred activity for this intent...

Can anyone can help this? is it error usage for android:priority?

Thanks!

回答1:

I haven't actually seen android:priority being taken into account when the system is resolving intents. I just tried setting a priority on an intent-filter that I use, but the system still gave me the resolution popup dialog, no matter what value I set my intent-filter's priority to.

I guess you'll just have to select the home screen activity you want to use (i.e. yours) and select the "Use by default..." checkbox.



回答2:

android:priority is only used on OrderedBroadcast intents, not the order of resolution for non-ordered broadcasts. Users select the default activity for a given action, which is why the dialog pops up. So, yes, you are using priority incorrectly.



回答3:

From your snippet, it seems that You are trying to launch your application. Priority is the one that should be given to the parent component w.r.t handling intents of the type described by the filter.

It provides information about the ability of an activity to respond to an intent that matches the filter, relative to other activities.It also controls the order in which broadcast receivers are executed to receive broadcast messages. Use this attribute only if you really need to impose a specific order in which the broadcasts are received, or want to force Android to prefer one activity over others.

The value must be an integer, such as "100". Higher numbers have a higher priority.



回答4:

// non-privileged applications can never define a priority > 0 (PKMS)