App Links Assistant Android Studio在第一个应用程序活动中打开

问题描述

我使用Android Studio中的“应用链接助手”来配置将通过我的应用打开的链接

一切正常。

但是我的问题是,当我通过该应用程序打开链接时,它会打开我单击链接的上一个应用程序中定义的活动。

例如:

如果我单击WhatsApp中的链接,则会看到以下内容

open link

当我使用该应用打开时,该应用将在WhatsApp中打开,如下图所示:

whatsapp opens

那么我怎么只能在我的应用程序中而不是在WhatsApp或其他应用程序中打开应用程序?

这是我此活动的AndroidManifest.xml代码

 <activity android:name=".extraLinks"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        >
        <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:scheme="http"
                android:host="www.jtube.live" />
        </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:scheme="https"
                android:host="www.jtube.live" />
        </intent-filter>
       
    </activity>

更新:我检查了我的Gmail和Chrome应用程序,如果从这些应用程序中打开,它们运行正常,那么我的问题仅限于Whatsapp应用程序...

解决方法

活动A开始活动B时,默认行为是:

在当前任务中创建活动B的新实例,并将其推送到后退堆栈。

要自定义这种行为,有一些选项:

  • 向开始特定活动的意图添加标志;
  • 为正在启动的活动
  • 设置launchMode属性;

当我们谈论其他应用程序时,第一个选择不在您的控制范围内。

由于以下原因,您在WhatsApp和Gmail应用程序中面临不同的行为:

Gmail使用FLAG_ACTIVITY_NEW_TASK为每个HTTP链接自定义意图,因此,应用程序中的活动在新任务中开始。 WhatsApp应用程序在启动任何处理特定HTTP链接的活动时未指定此标志。

在您的情况下,自定义此行为的唯一方法是使用launchMode属性作为处理应用程序链接的目标活动的属性。有两种可能的值适用于您的情况:singleTasksingleInstance

检查这些链接以了解其工作原理:

,

尝试一下:

<intent-filter android:label="app_label">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.LAUNCHER"/>
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data
       android:scheme="https"
       android:host="www.jtube.live" />
</intent-filter>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...