How to create direct links to the content of the app... Very usefull

Beck

Member
XNullUser
Joined
Sep 9, 2021
Messages
62
Reaction score
10
Points
8
NullCash
51
When a clickable link or programmatic request invokes a web URI intent, the Android system tries the following actions, in sequential order, until the request is successful:

Opens the user's preferred app that can handle the URI, if one is designated.
Open the only available app that can handle the URI.
Allows the user to select an app from a dialog.
Follow the steps below to link to and test your content. You can also use the Android App Links Wizard in Android Studio to add Android App Links.

How to Add Intent Filters for Inbound Links
To link to the content of your app, add an intent filter that contains these elements and attribute values in your manifest:

<action>
Specifies the intent action ACTION_VIEW so that the intent filter can be accessed from Google Search.
<data>
Add one or more <data> tags; these must represent a URI format that is resolved in the activity. At a minimum, the <data> tag must include the android: scheme attribute.
You can add more attributes to improve the type of URI that the activity accepts. For example, there may be multiple activities that accept similar URIs, yet differ simply in the path name. In this case, use the android: path attribute or its pathPattern or pathPrefix variants to differentiate the activity that the system should open based on the different URI paths.

<category>
Includes the BROWSABLE category. It is required so that the intent filter can be accessed from a web browser. Without it, when a link is clicked within a browser, it is not redirected to your app.
Also includes the DEFAULT category. In this way, your app can respond to implicit intents. Without it, the activity can only be started if the intent specifies the name of the app component.

The following XML snippet shows how you can specify an intent filter in your manifest for direct links. The URIs "example: // gizmos" and "http://www.example.com/gizmos" resolve this activity.


<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>

Note that the two intent filters only differ in the <data> element. While it is possible to include multiple <data> elements in the same filter, it is important that you create separate filters when your intention is to declare unique URLs (such as a specific combination of scheme and host), as multiple <data> elements are merged in the same intent filter to represent all variations of their combined attributes. For example, consider the following:


<intent-filter>
...
<data android: scheme = "https" android: host = "www.example.com" />
<data android: scheme = "app" android: host = "open.my.app" />
</intent-filter>

It may appear that this only supports https://www.example.com and app: //open.my.app. However, it is also compatible with app: //www.example.com and https://open.my.app.

Once you've added intent filters with URIs for activity content to your app's manifest, Android will be able to route any Intents that have matching URIs to your app at runtime.

For more information on defining intent filters, see Allow other apps to start your activity.
 
Top