Understanding Activity Calls with Multiple Data Tags for One Intent-filter

Asked 2 years ago, Updated 2 years ago, 37 views

In some cases, you may want to launch activities that support multiple implicit intents. The specified issue of Intent is unable to start.

The Android Manifest.xml app you want to launch (activity) is set as follows:

<activity
    android:name="com.sample.testapp.MainActivity"
    android:exported="true"
    android: label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>

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

        <data
            android: scheme="testapp"/>
        <data
            android: host="hoge"
            android: pathPrefix="/fuga"
            android: scheme="https"/>
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
 </activity>

As mentioned above, two data tags are set: http and custom scheme testapp. At this time, the "testapp" scheme does not respond.

adb shell am start-a android.intent.action.VIEW-d "testapp:"

The startup Intent is specified as above.

Starting:Intent {act=android.intent.action.VIEW dat=testapp:} Error: Activity not started, enable to resolve Intent {act=android.intent.action.VIEW>dat=testapp:flg=0x10000000}

The error is as above.

What is the right way to invoke activity for Activity implementing such filters? Please let me know if anyone knows any effective means.

android

2022-09-30 12:04

2 Answers

There seems to be a misunderstanding in handling data in the int-filter. For this sample code with multiple data elements in a single intent-filter,

<intent-filter>
    ...omitted...
    <data
        android: scheme="testapp"/>
    <data
        android: host="hoge"
        android: pathPrefix="/fuga"
        android: scheme="https"/>
</intent-filter>

At first glance, each data element reads like an OR specification. The actual behavior is "the scheme attribute specifies testapp or https, and the AND host attribute is hoge AND pathPrefix attribute is /fuga".If you want to invoke Activity with the sample code, use the

adb shell am start-a android.intent.action.VIEW-d "testapp://hoge/fuga"

Or

adb shell am start-a android.intent.action.VIEW-d "https://hoge/fuga"

You can boot to the .

http://developer.android.com/guide/topics/manifest/data-element.html is familiar with data elements.


2022-09-30 12:04

Head office SO has similar questions and answers.

Why don't you separate <intent-filter>?

<activity
  android:name="com.sample.testapp.MainActivity"

  android:exported="true"
  android: label="@string/app_name">
  <intent-filter>
    <action android:name="android.intent.action.VIEW"/>

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

    <data
      android: scheme="testapp"/>
  </intent-filter>
  <intent-filter>
    <action android:name="android.intent.action.VIEW"/>

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

    <data
      android: host="hoge"
      android: pathPrefix="/fuga"
      android: scheme="https"/>
  </intent-filter>
  <intent-filter>
    <action android:name="android.intent.action.MAIN"/>

    <category android:name="android.intent.category.LAUNCHER"/>
  </intent-filter>
</activity>


2022-09-30 12:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.