【问题标题】:How to open the android app when user try to hit dynamic link in mobile browser当用户尝试在移动浏览器中点击动态链接时如何打开 android 应用程序
【发布时间】:2016-06-06 08:54:24
【问题描述】:

我使用 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]

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

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

【问题讨论】:

  • 我想你需要的是Intent Handler
  • 那已经在那里了。用处理程序更新了问题。
  • 对不起。我没有注意到.. 是否出现任何错误?或者任何可以确认它是否真的通过你的代码的日志?
  • 它没有显示任何错误或日志。我认为它没有通过我的代码。
  • @user3559471 你是如何创建链接的?

标签: android firebase firebase-dynamic-links


【解决方案1】:

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

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

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

<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="google.com"
        android:scheme="https"
        android:pathPattern=".*" />
</intent-filter>

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

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

【讨论】:

  • 我尝试了您建议的更改。在笔记本电脑浏览器和移动浏览器中打开谷歌页面的长网址和短网址。这是长网址,如下所示:https://.app.goo.gl/?link=<a href="/default/index/tourl?u=aHR0cHM6Ly9nb29nbGUuY29tJmFwbj08cGFja2FnZQ%3D%3D" rel="nofollow" target="_blank">google.com&amp;apn=&lt;package</a>name&gt;
  • 笔记本电脑浏览器按预期工作。你如何测试网址?尝试单击 URL(例如,在网页或电子邮件中),而不是在浏览器地址窗口中写入。我假设您的 与您的应用程序包名称完全相同。
  • 我尝试点击链接(通过短信发送)。重新检查包名,是正确的。这可能吗,因为我的应用不在 Play 商店中,所以问题正在发生?只是通知一下,我已经在本地安装了应用程序(不是通过 Play 商店)
  • 我认为应用程序不需要在 Play 商店中才能正常工作。我的应用程序在那里,但是当应用程序已经安装在设备上时,我认为不涉及 Play 商店。 (如果我没有安装应用程序,该链接将打开正确的 Play 商店页面,但在开发过程中我自然会使用本地安装的应用程序)。不过,对此没有 100% 的了解。我建议您接下来尝试给出“al=myscheme://myhost”,您需要在清单中设置它们并在代码中实现对它们的处理。但是你可以完全灵活地做任何事情。
  • 另外你应该确保浏览器没有被设置为google.com的默认处理程序(应用程序管理->你的应用程序->默认启动)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-08
  • 1970-01-01
  • 2012-03-30
  • 2022-12-21
  • 2014-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多