What is the qualifier for an empty host in an intent filter?

I am trying to configure the application for these schemes:

my-app: // product / XXX

and

my-app: //

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

I don’t want to specify β€œ*” as an android host, as there are other actions that handle different actions, and then they don’t open directly, but I get a selection dialog to choose which action should be 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!

+5
source share
1 answer

Not having a host (or, more formally authoritative) part in the URI, this is completely normal. Think of the commonly used file:///tmp/example.file

Note that the painless hierarchical URI is not opaque (for example, mailto: john@example.com ), but has a path. Like a file URI, the host name is replaced with a single / .

Therefore, your URI should be of the form my-app:///product/XXX . An Intent filter might 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 receive a warning about an empty host name, which is absolutely normal. This warning is the result of checking the Firebase App Indexing , which, I believe, only makes sense if you have a website (from which you would take the hostname, i.e. all the URIs then).

Since you won’t use indexing anyway, you can remove the warning by adding the following lint.xml to your project:

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

See the URI specification and Wikipedia entry in URI files for more details.

+1
source

Source: https://habr.com/ru/post/1235547/


All Articles