Reputation: 9653
As per this -
<activity
android:name="com.example.android.GizmosActivity"
android:label="@string/title_gizmos" >
<intent-filter android:label="@string/filter_view_http_gizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>
<intent-filter android:label="@string/filter_view_example_gizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos” -->
<data android:scheme="example"
android:host="gizmos" />
</intent-filter>
</activity>
Regarding the first Intent filter i understand that when clicked link is “http://www.example.com/gizmos” it will redirect to app page with that intent filter. But regarding second intent filter “example://gizmos” this doesn’t looks like a valid web url and no valid web url will begin with this.Then why does apps use such kind of intent filters?I have seen so many such types of intent filters where combining host and scheme doesn’t make a proper web url.I understand that doc mention it as URI not URL.How can such URIs like “example://gizmos” can be opened?Can such URIs be opened from outside app?
Upvotes: 0
Views: 268
Reputation: 19243
have you tested this example://gizmos
URI? e.g. by putting on some web site and opening by clicking link on it in some web browser? or by putting some button in your code and trying to open this scheme using default picker of system Intent.createChooser
when onClick
note that when you obtain http://
link in e.g. some message and click it then system will show picker: your app and web browsers, as these kind of apps have declared openable with scheme="http"
without any further limitation (e.g. to host
value). when you click example
scheme then default picker will look for app which declares it can open such link, without your app it will show that this link isn't "openable", so this is app-only link
btw. this isn't best approach currently and it works best on native level - communicating between two native apps with checking that other side is installed - not for mixing with web links. best would be to integrate App Linking (which in fact is extended Deep Linking). this pattern works only on web scheme
s (like http
or https
), but can automatically redirect from browser to your app if installed (if not, stays on web) and server is declaring that web URI can/should be redirected to native app
note that there are other default non-web scheme
s, like well-known mailto:<mail_address>
or tel:<number>
- works same way: system will look for an app declaring can open such URI. these won't be handled by web browser, these aren't web protocols
Upvotes: 1