6

Let us say there is a website https://www.example.com and we are listening to https://www.example.com/product in Android App with following intent filter

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data
        android:host="www.example.com"
        android:pathPrefix="/product"
        android:scheme="https" />
</intent-filter>

And the file assetlinks.json is also hosted on example.com

The Android App links are working fine as expected.

Now, if the user went to browser and open example.com and the user clicks on https://example.com/product which will be opened in app but we want to block app from opening only if the user is on our website

Any help will be appreciated.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
codepeaker
  • 420
  • 8
  • 15
  • AFAIK chrome won't open your application if the current url has the same domain name as the url the user clicked. (beware that `https://example.com` and `https://www.example.com` are not using the same domain name) – Simon Marquis Jun 17 '19 at 09:54
  • Chrome doesn't open app, its the android system in case of Android App links – codepeaker Jun 17 '19 at 11:26

3 Answers3

1

After looking a lot, The only workaround i was able to find to open web instead of app is redirection from web -> app (redirection logic) -> website.

An important thing, I noticed is that the App is never invoked if the page is developed in React or Angular and is not based on JSP. In our case, We were using Tomcat server, So whenever user navigate to different page, The Android System get to know that a new page is opened in browser, which makes Android System to open Android App if listening to that url specified in the intent filter. However, this doesn't happen if the page is designed in React and Angular.

Now, this is really difficult for me to describe as i am not a web developer and this is what the web developers told and i experienced with both JSP and React pages.

codepeaker
  • 420
  • 8
  • 15
0

I think the web-developers might have told you cheese ...because it's all about the URL and not the content. Tap-hold in Chrome and then "open in new tab" works without passing the new URL through the intent filter... and you'll fail to read the URL from Chrome, therefore you can ditch that approach.

All you can do to work around the problem you've created by adding the intent-filter would be to setup two sub-domains and then filter only for one for them, while still displaying the same content on both of them (needs a canonical meta tag in HTML) - then you can simply use the page as usual and nothing will trigger the intent filter.

And in order to still be able to open the app trough the intent filter ... just add a button, which links to the other one sub-domain, which the intent filter is matching. Other approaches might be illogical or otherwise problematic.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • No, we don't want two subdomain. All we want is, When the user is already on the site i.e. on the home page(No intent Filter for home page in app) and if the user clicks on any link then that shouldn't redirect to the app even if it is set up as an intent filter. Now, we experienced the needed flow when the web app is developed in React or Angular. – codepeaker Feb 10 '20 at 08:50
-1

Well, based on official Android documents, you need to remove BROWSABLE category from intent-filter on Manifest.

https://developer.android.com/training/app-links/deep-linking

From document for who have difficulties to open a url and read a document :

Include the BROWSABLE category. It is required in order for the intent filter to be accessible from a web browser. Without it, clicking a link in a browser cannot resolve to your app.

That means, if you don't want browser to direct to your app, JUST remove BROWSABLE category. That's all.

So your Manifest will look like below :

<intent-filter android:autoVerify="true"
tools:ignore="AppLinkUrlError">

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<data
    android:host="www.example.com"
    android:pathPrefix="/product"
    android:scheme="https" />
</intent-filter>

You will get an "AppLinkUrlError" so you can add;

tools:ignore="AppLinkUrlError"

to suppress it.

dcanbatman
  • 165
  • 1
  • 13
  • As you can see in my Question, we want the user to open our website the Home Page for which we are not listening using app links but as soon as the user clicks anything that could be related to app links should not be opened from the apps. Because the user is already in the browser and browsing through the website, abrupt navigation to the app is not needed. – codepeaker Feb 09 '20 at 19:47
  • We want the user to resolve to the app when there is any link of the product page on Google Search but if the user is in the site itself and after that, the user clicks on any product page link then the link should not resolve to the app. – codepeaker Feb 11 '20 at 07:26
  • I know this is not possible as of now because android app links are not made as if they can determine if the user is on the site or on Google search. Overall we don't want the existing web flow to get interrupted. – codepeaker Feb 11 '20 at 07:30