1

I just finished setting up App Indexing for my website's Android app and I did a few tests by passing https://www.example.com/test and https://example.com/test according to the instructions specified in https://developers.google.com/app-indexing/android/test (Testing URLs with Android Studio)

This is my intent filter in my Android Manifest:

<intent-filter android:label="@string/filter_title_default">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https"
          android:host="example.com"
          android:pathPrefix="/test" />
</intent-filter>

I noticed that https://www.example.com/test fails, but not https://example.com/test. How do I fix this, other than specifying another intent filter for www.example.com/test?

terencey
  • 3,282
  • 4
  • 32
  • 40

2 Answers2

0

As far as I know, each host should be added in a new intent filter. You can refer to this doc for more info.

Cheers, MB

Mia
  • 226
  • 1
  • 2
0

You can specify multiple data elements for your intent filter, for all URLs you need to handle with your activity.

To handle both www and non-www links to your domain you can change your intent filter to this:

<intent-filter android:label="@string/filter_title_default">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https"
          android:host="example.com"
          android:pathPrefix="/test" />
    <data android:scheme="https"
          android:host="www.example.com"
          android:pathPrefix="/test" />
</intent-filter>

Or to handle example.com and any subdomain, you can include a wildcard at the beginning of the host:

<intent-filter android:label="@string/filter_title_default">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https"
          android:host="example.com"
          android:pathPrefix="/test" />
    <data android:scheme="https"
          android:host="*.example.com"
          android:pathPrefix="/test" />
</intent-filter>

Also, if you want to match all your domain URLs, you must remove the pathPrefix attribute completely, as setting it to "/" doesn't work as expected.