5

I created an intent filter to one of my activities in order to be able to launch it via deep linking :

     <activity
        android:name="com.myapp.activities.LoginActivity"
        android:label="@string/app_name">
        <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="myserver.com"
                android:pathPrefix="/product/"
                android:scheme="https" />
            <data
                android:host="www.myserver.com"
                android:pathPrefix="/product/"
                android:scheme="https" />
        </intent-filter>
    </activity>

Mostly everything works ok. When im clicking these links from any email client, or from whatsapp messages, or from tweets, picking any browser in the app chooser dialog, it identifies my intent filter and opens the right activity. Which means my intent filter was defined ok.

But... there are some cases where i need to click these links from the device's calendar or from HTMLViewer. In these cases my app is not opened when i select the stock browser. It just opens the browser with the URL address. This just happens when i select the device's stock browser. When i select a different browser (e.g Chrome) the app is opened correctly. Any idea why is that ? Or how can i enable deep linking to work in all cases ?

2 important notes :

  1. Im testing this for now on Galaxy S3. I know the browser on Galaxy devices is not considered "stock" per se. Still i would like to find a solution that will work on all devices.

  2. The url address for the deep linking is an actual address that runs a javascript on the browser side. For cases where the app is not installed on the user's device it redirects him to the play store. Im saying that because im also open to server side solutions if they might solve this issue. I saw this Question but the answer there doesn't work for me.

Anyway, I really appreciate any help from the SO community. This has been a pain in the ass for me (and im sure for others).

Thanks.

Community
  • 1
  • 1
AsafK
  • 2,425
  • 3
  • 32
  • 38

1 Answers1

2

I can't see anything obviously wrong with what you have posted but you say:

In these cases my app is not opened when i select the stock browser.

is your app not appearing as an option to choose from when you click the link? If your filter matches it should be an option no? If you select the default browser I don't blame it for swallowing the intent.

Anyway, if you cannot get it working, you could use some client side web code to have the urls fire out to the app if installed and off to the store if not, and modify the URI scheme to your own custom one. See this answer:

https://stackoverflow.com/a/8237102/1137254

Then you could maybe filter for both:

<activity
    android:name="com.myapp.activities.LoginActivity"
    android:label="@string/app_name">
    <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="myserver.com"
            android:pathPrefix="/product/"
            android:scheme="https" />
        <data
            android:host="www.myserver.com"
            android:pathPrefix="/product/"
            android:scheme="https" />
        <data
            android:host="product"
            android:scheme="asafk" />
    </intent-filter>
</activity>

UPDATE: I ran a test on a galaxy s3 myself and found that your pathPrefix is set a little wrong. Your current filter works with a URL like this https://myserver.com/product/blah but not https://myserver.com/product

So here is your update intent filter (notice the trailing forward slash is omitted):

 <activity
    android:name="com.myapp.activities.LoginActivity"
    android:label="@string/app_name">
    <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="myserver.com"
            android:pathPrefix="/product"
            android:scheme="https" />
        <data
            android:host="www.myserver.com"
            android:pathPrefix="/product"
            android:scheme="https" />
    </intent-filter>
</activity>

Please let me know if this solves your problem. Your user may still select the wrong option so I still recommend following my other recommendation of having some Javascript on the page that attempts to open app (it's pretty basic but I think it's widely used for this).

Hope this fixes your problem.

Community
  • 1
  • 1
Sam
  • 3,453
  • 1
  • 33
  • 57
  • Thanks for the reply. First, i want to clarify, even if my app is installed on a device with an intent filter mapped to a url, clicking this url will allways want to open a browser as a first step. Only after selecting a browser it will show you the option to select my app. The first step is the problemtic one. Selecting the stock browser doesnt always show you my app in the second step. – AsafK Jul 04 '14 at 11:15
  • Secondly, your suggested solution says _"you could use some client side web code to have the urls fire out to the app if installed and off to the store if not"_. How exactly do you check if the app is installed or not ? **There is no way to know that** and that is why you put an actual url in the intent filter. If the app is installed then it is supposed to be launched. If not, than the url is opened in a browser (and you can redirect the user to the store). – AsafK Jul 04 '14 at 11:22
  • added an update that seems to fix your problem for me – Sam Jul 04 '14 at 14:33
  • I read the link you posted and i actually already ommited the slash before (in addition to adding android:pathPattern=".*" as suggested [here](https://code.google.com/p/android/issues/detail?id=22971)) and still no dice. Also, i already implemented a javascript for redirecting the user. As i already mentioned in my question, in my case it is for the store only. Redirecting the user using a cusom schema is not recommended because we can't know for sure whether the app is installed or not. And in cases where its not we will just get to a dead end. – AsafK Jul 04 '14 at 15:01
  • You're saying that you tested this on Galaxy S3 and it worked. Did you try clicking the url from the S-Planner or HTMLViewer ? Cause these are where i see this issue happening. – AsafK Jul 04 '14 at 15:03
  • Yup, just clicked a link from s-planner and got an intent including my app. Heres a screenshot: http://imgur.com/msd9seO – Sam Jul 04 '14 at 15:17
  • (obvious question: have you cleared your defaults or totally uninstalled and reinstaled your app?) – Sam Jul 04 '14 at 15:17
  • "Redirecting the user using a cusom schema is not recommended because we can't know for sure whether the app is installed or not. And in cases where its not we will just get to a dead end." This is why there is a timeout in the javascript linked to go to the store. – Sam Jul 04 '14 at 15:18
  • ... did you have any luck with my demo? – Sam Jul 07 '14 at 11:15
  • There was one small piece of information i forgot to mention. My links were created using a url shortener. So basically when the user clicked a link (short one. Not mapped to an intent), the browser was opened and the link was translated to the real url (long one. Mapped to an intent). This was where i saw the problem. Using chrome the browser was able to redirect the long url to my app's intent. Samsung stock browser wasn't able to do that. When i stopped using the url shortener everything started working correctly. Nevertheless, This is a bug in Samsung browser. – AsafK Jul 08 '14 at 13:51
  • right. that was a fairly important detail. have a look here http://stackoverflow.com/questions/12036793/android-browser-facebook-redirect-does-not-always-trigger-intent-for-url – Sam Jul 08 '14 at 14:10
  • The same link was already attached to my question here. See above (the 2nd "important note"). – AsafK Jul 08 '14 at 16:23
  • Looks like you need to ditch the URL shortener. (You could always 'unshorten' the URL in your app) – Sam Jul 14 '14 at 08:38