2

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:

open link

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

whatsapp opens

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:

 <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>

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...

locrizak
  • 12,192
  • 12
  • 60
  • 80
Fox
  • 103
  • 11
  • Everybody can help? I cant find answer! – Elidor Oct 06 '20 at 13:18
  • Please, provide a definition in AndroidManifest.xml for an activity to which URL was mapped. – Николай Гольцев Oct 07 '20 at 10:07
  • @НиколайГольцев I added code from manifest I will be happy for you help! – Fox Oct 07 '20 at 10:49
  • Did you try to open your app through a link from another app, e.g Gmail? I can't replicate this behavior. – Николай Гольцев Oct 07 '20 at 11:36
  • @НиколайГольцев yes, from gmail and chrome its working well! I don't know what todo:( – Fox Oct 07 '20 at 11:38
  • This is likely because yours is a browser app. Which is why I see Chrome as the other choice. This happens if you open any app and you click a link that tries to open a browser. If you chose Chrome I feel you'll get the same result. Like I do when I open a link on LinkedIn App it opens it as a webpage but within the LinkedIn app itself. If yours was a native app that wasn't a browser, let's say a payment app or a game, it would open it as a separate app. – LeoNeo Oct 07 '20 at 17:03

2 Answers2

2

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:

0

try this:

<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>
Joseph Utulu
  • 236
  • 1
  • 12