Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the specifier for empty host in intent-filter?

I'm trying to make my app respond to these schemes:

my-app://product/XXX

and

my-app://

The following code works, but I'm getting warning that android:host cannot be empty. It still works, but - is there a correct way to specify empty host?

I don't want to specify "*" as android-host, as there are other activities that handle different actions, and then they don't open directly, but I'm getting a chooser dialog to select which activity should open.

<activity android:name=".ui.OpenerActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="portrait" >
        <intent-filter>
            <data android:scheme="my-app" />
            <data android:host="product" />
            <data android:host="" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>

Thanks a lot!

like image 770
kkazakov Avatar asked Nov 09 '15 14:11

kkazakov


1 Answers

Not having a host (or, more formally authority) part in you URI ist absolutely fine. Think about the commonly used file:///tmp/example.file

Note though that a hostless, hierarchical URI is not opaque (like mailto:[email protected]), but has a path. Like the file-URI the hostname gets replaced by a single /.

Your URI should therefore be of the form my-app:///product/XXX. The Intent Filter could look like this:

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

  <action android:name="android.intent.action.VIEW"/>

  <data android:host=""/>
  <data android:scheme="my-app"/>
  <data android:pathPrefix="/product"/>
  <data android:pathPattern=".+"/>
</intent-filter>

You will still get the warning about the empty hostname, which is absolutely ok. This warning is the result of a check for Firebase App Indexing, which I guess only makes sense in the presence of a website (from which you would take the hostname, ie. whole URIs then).

Since you will not use the indexing anyway, you can remove the warning by adding the following to your project's lint.xml:

<!-- no app indexing without a hostname -->
<issue id="GoogleAppIndexingUrlError" severity="ignore"/>

For more details, looks at the URI spec and Wikipedia entry on file-URIs.

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

Max Hille