android - 在另一个应用程序 Android 中启动一个应用程序

标签 android firebase android-intent firebase-dynamic-links

我的问题是如何在应用程序 B 中启动应用程序 A,使应用程序 A 通过深度链接在应用程序 B 中?

在下面的第一张图片中,Debug 应用显示为独立于 Slack 的应用(新代码,Firebase 深层链接)。在第二张图片中,Debug 应用似乎在 Slack 应用中(旧代码,Android 深度链接)。我想使用 Firebase 深层链接并在其他应用程序(Slack、Gmail 等)中显示调试应用程序。

enter image description here enter image description here

任何人都可以通过下面的代码让我知道如何实现吗?

旧代码,Android 深度链接:

AndroidManifest

<activity
    android:name=".activity.SplashScreenActivity"
    android:screenOrientation="portrait"
    android:theme="@style/SplashTheme">
    <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" />
        <!-- Accepts URIs that begin with "abc://flights” -->
        <data
            android:host="sales"
            android:scheme="abc" />
        <data
            android:host="deals"
            android:scheme="abc" />
    </intent-filter>
</activity>

Activity :

Intent intent = new Intent(SplashScreenActivity.this, BottomNavBarActivity.class);

        //Deep Linking Content
        Uri deepLinkData = getIntent().getData();
        if (deepLinkData != null) {
            intent.putExtra(EXTRA_DEEP_LINK, deepLinkData.getHost());
        }

        startActivity(intent);
        overridePendingTransition(R.anim.splash_fade_in, R.anim.splash_fade_out);
        finish();

新代码,Firebase 深层链接:

安卓 list :

<activity
        android:name=".activity.SplashScreenActivity"
        android:screenOrientation="portrait"
        android:theme="@style/SplashTheme">
        <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="abc.app.goo.gl"
                android:scheme="http"/>
            <data
                android:host="abc.app.goo.gl"
                android:scheme="https"/>
        </intent-filter>
    </activity>

Activity :

FirebaseDynamicLinks.getInstance()
            .getDynamicLink(getIntent())
            .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
                @Override
                public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                    // Get deep link from result (may be null if no link is found)
                    Uri deepLink = null;
                    if (pendingDynamicLinkData != null) {

                    // Start the activity through intent, same as before.

                    }
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.v(TAG, "Firebase deep link failure");
                }
            });

最佳答案

它取决于发送 Intent 的应用程序,例如它们是否通过了 FLAG_ACTIVITY_NEW_TASK。我怀疑这里的区别在于 Slack 处理链接的方式 - 他们可能会以不同于其他格式的方式处理 Web URL(您的旧链接具有非标准方案)。

关于android - 在另一个应用程序 Android 中启动一个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48493908/

相关文章:

android - 获取随机列表项android

android - 如何使用 ViewModel(MVVM) 将对象从 fragment 传递到 Activity 详细信息 View ?

java - Firebase 数据映射到 Java 类

javascript - AngularJS 1.3.8 中的 "Argument ' BrowseController ' is not a function, got undefined"

javascript - 如何在 firebase 云函数中使用 javascript setTimeout 函数

java - android - Intent 者的子 Activity

java - 从 Activity 返回结果

java - 想先找到焦距,然后使用 opencv android 实时检测到人脸的距离

android - 找不到符号 Android React Native

android - 无法获得哪个 Android 版本支持 chromecast 应用程序的答案