当用户尝试在移动浏览器中点击动态链接时,如何打开Android应用程序

时间:2016-06-06 08:54:25

标签: android firebase firebase-dynamic-links

我使用firebase控制台创建了动态链接。我的设备上安装了一个本地应用程序(谷歌游戏商店中尚未安装的应用程序)。

这是处理动态链接的清单文件中的代码。

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

当我在移动浏览器中打开动态链接时,它不会将我重定向到应用程序。而是在移动浏览器中打开链接。

当用户尝试在移动浏览器中点击动态链接时如何打开应用程序?

1 个答案:

答案 0 :(得分:1)

您的网址和清单都存在一些问题。 “link”参数还需要包含该方案,因此只需最少的更改:

RawUrl

(请注意添加的https://),在使用该链接时,您的清单应如下所示:

https://<code>.app.goo.gl/?link=https://google.com&apn=<package name>

您可以在firebase网页上创建短网址之前使用完整网址测试您的应用。这有助于您确保在创建实际使用的简短网址之前获得应用程序。

使用http / https方案时,android首先应该询问您是要打开浏览器还是应用程序。我更喜欢使用“al”和应用程序特定方案在我的应用程序上打开视图。

相关问题