android - Firebase 动态链接未打开应用

标签 android firebase firebase-dynamic-links

我已经在我的设备上本地开发了一个 android 应用程序(应用程序还没有在 android play 商店上)。我有以下逻辑来获取 MainActivity 中的深层链接。

GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, null)
            .addApi(AppInvite.API)
            .build();

    // 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);

                                Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
                                // Handle the deep link. For example, open the linked
                                // content, or apply promotional credit to the user's
                                // account.

                                // ...
                            } else {
                                Log.d(TAG, "getInvitation: no deep link found.");
                            }
                        }
                    });

我使用 Firebase 控制台构建了一些动态链接并在移动浏览器中打开。但它没有打开我的应用程序并到达行 String deepLink = AppInviteReferral.getDeepLink(intent);

而是在移动浏览器中打开 URL。

如何在使用 firebase 动态链接时打开应用程序并处理 Activity 中的深度链接??

编辑:

我在 list 文件中有 Intent 过滤器。

<activity android:name="MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:host="example.com" android:scheme="http"/>
            <data android:host="example.com" android:scheme="https"/>
        </intent-filter>
    </activity>

最佳答案

Action View 和 Action Main 都属于不同的 Intent 类别。因此,您需要像这样将它们放在不同的 block 中:

 <activity android:name=".DynamicLinkActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </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="example.com"
                android:scheme="http" />
            <data
                android:host="example.com"
                android:scheme="https" />
        </intent-filter>
    </activity>

关于android - Firebase 动态链接未打开应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41209129/

相关文章:

java - 过滤器将 ArrayList<object> 添加到 HashMap

java - 接收图像并使用 TCP 套接字显示它? (安卓)

angular - 如何在我的 Angular 应用程序中使用 Firebase Admin SDK?

带有查询参数的 Firebase 动态链接

ios - 我们可以在没有 page.link 域的情况下使用 firebase 动态链接吗?

android - layout_weight =".4"看起来比 layout_weight =".6"大

java - Android 在 Fragment 之间传递数据

typescript - Firebase错误: Firebase: Firebase App named '[DEFAULT]' already exists with different options or config (app/duplicate-app)

java - 如何从 Firebase 存储中检索图像 url 以进行 JSON 解析?

android - Firebase动态链接与动态参数?