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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With