我使用 firebase 控制台创建了动态链接。我的设备上安装了一个本地应用程序(应用程序尚未在 google play store 上)。
这是清单文件中用于处理动态链接的代码。
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- [START link_intent_filter] -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="<code>.app.goo.gl/"
android:scheme="https"
android:pathPattern=".*" />
</intent-filter>
<!-- [END link_intent_filter] -->
</activity>
这是活动中的意图处理程序
// [START build_api_client]
// Build GoogleApiClient with AppInvite API for receiving deep links
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(AppInvite.API)
.build();
// [END build_api_client]
// [START get_deep_link]
// Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
// would automatically launch the deep link if one is found.
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
@Override
public void onResult(@NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
// [START_EXCLUDE]
// Display deep link in the UI
//((TextView) findViewById(R.id.link_view_receive)).setText(deepLink);
Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
// [END_EXCLUDE]
} else {
Log.d(TAG, "getInvitation: no deep link found.");
}
}
});
// [END get_deep_link]
当我在移动浏览器中打开动态链接时,它不会将我重定向到应用程序。而是在移动浏览器本身中打开链接。
当用户尝试在移动浏览器中点击动态链接时如何打开应用程序?