[Android] How to enable the “deep linking” for app content?
Sometimes, we need to provide a way to enter an Android application from web browser. In that case, you can send the intent by a hyperlink on the web page. When user clicks the hyperlink, browser will try to send the intent on Android system. Then, the system will switch to application from web browser and the application also receives the content from browser that sent.
[data_type].[key]=[value];
We generate the hyperlink contains the URI on the web. A html example is by following,
<html>
<head>
<title>launch application from browser</title>
<meta http-equiv = "Content-Type" content = "text/html; charset=utf-8">
</head>
<body>
<p>
<a href="intent:/#Intent;scheme=test_scheme;package=com.test.application;S.string_extra=data;end">Click Me!</a>
</p>
</body>
</html>
<intent-filter>
<data android:scheme="test_scheme">
<action android:name="android.intent.action.VIEW">
<category android:name="android.intent.category.DEFAULT">
<category android:name="android.intent.category.BROWSABLE">
</intent-filter>
Because the security issue, we add the BROWSABLE category to prevent intent sender is not web browser.
and here is the example for getting the intent’s extra data,
Intent intent = getIntent();
if (intent != null) {
if (intent.getAction().contentEquals(Intent.ACTION_VIEW)) {
String userId = intent.getStringExtra(“key”);
// process another operations
}
}
發佈留言
很抱歉,必須登入網站才能發佈留言。