App Links Assistant Android Studio open in first app activity

huangapple go评论88阅读模式
英文:

App Links Assistant Android Studio open in first app activity

问题

我在Android Studio中使用“App Links Assistant”来配置通过我的应用打开的链接。

一切工作正常。

但是我的问题是,当我通过应用打开链接时,它会在我之前点击链接的先前应用中打开定义的活动。

例如:

如果我在WhatsApp中点击链接,我会看到类似于这样的内容:

App Links Assistant Android Studio open in first app activity

当我使用应用程序打开时,应用程序会在WhatsApp内部打开,如图所示:

App Links Assistant Android Studio open in first app activity

那么,我如何才能让应用仅在我的应用中打开,而不是在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应用中...

英文:

I use the 'App Links Assistant' in Android Studio to configure links that will be opened through my app.

Everything works well.

But my problem is that when I open the link through the app, it opens the activity defined within the previous app where I clicked on the link.

For example:

If I click on a link in WhatsApp I see something like this:

App Links Assistant Android Studio open in first app activity

And when I open using the app, the app opens within WhatsApp as seen in this image:

App Links Assistant Android Studio open in first app activity

So how can I open the app only in My app and not within WhatsApp or another app?

Here my AndroidManifest.xml code of this activity:

 &lt;activity android:name=&quot;.extraLinks&quot;
        android:configChanges=&quot;keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize&quot;
        &gt;
        &lt;intent-filter&gt;
            &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;

            &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
            &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;

            &lt;data
                android:scheme=&quot;http&quot;
                android:host=&quot;www.jtube.live&quot; /&gt;
        &lt;/intent-filter&gt;
        &lt;intent-filter&gt;
            &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;

            &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
            &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;

            &lt;data
                android:scheme=&quot;https&quot;
                android:host=&quot;www.jtube.live&quot; /&gt;
        &lt;/intent-filter&gt;
       
    &lt;/activity&gt;

update: I checked my Gmail and Chrome apps and if I open from those apps its working well, so my problem with Whatsapp app only...

答案1

得分: 2

当活动A启动活动B时,默认行为是:

在当前任务中创建活动B的一个新实例,并将其推送到返回栈。

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

  • 在启动特定活动的意图中添加标志(flags);
  • 为被启动的活动设置launchMode属性;

当涉及其他应用程序时,第一个选项超出了您的控制。

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

Gmail针对每个HTTP链接自定义意图,并使用FLAG_ACTIVITY_NEW_TASK,因此,您的应用程序中的活动会在新任务中启动。WhatsApp应用程序在启动处理特定HTTP链接的任何活动时都没有指定此标志。

在您的情况下,自定义此行为的唯一方法是通过调整处理应用链接的目标活动的launchMode属性。对于您的情况,有两个可能适用的值:singleTasksingleInstance

查看以下链接以了解其工作原理:

英文:

When activity A starts activity B the default behavior is:

A new instance of activity B is created within a current task and pushed to the back stack.

To customize such behavior there are some options:

  • add flags to the intent that starts a specific activity;
  • set launchMode attribute for an activity being started;

The first option is out of your control when we talk about other applications.

You face different behavior within WhatsApp and Gmail applications because of the following:

Gmail customizes intents for every HTTP link with FLAG_ACTIVITY_NEW_TASK and consequently, activity in your application starts within a new task. WhatsApp application doesn't specify this flag when it starts any activity which handles a specific HTTP link.

In your case, the only way to customize this behavior is to play with launchMode attribute for target activity that handles the app link. There are two possible values applicable to your case: singleTask or singleInstance.

Check these links to understand how it works:

答案2

得分: 0

请尝试这样做:

<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>
英文:

try this:

&lt;intent-filter android:label=&quot;app_label&quot;&gt;
    &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;
    &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&gt;
    &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
    &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;

    &lt;data
       android:scheme=&quot;https&quot;
       android:host=&quot;www.jtube.live&quot; /&gt;
&lt;/intent-filter&gt;

huangapple
  • 本文由 发表于 2020年10月2日 19:42:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/64170937.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定