Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http 302 redirect to deep link does not work in Android

We have an app in iOS and Android. Both of them are implement the same deep link (e.g. myapp://home/?abc=xxx&bcd=yyy)

We have tested in iOS and Android, the deep link is worked and it can open our application.

Then we create an API service. (e.g. https://myapp.com/testing/1234568)

When the user click on this link, it will determine whether the user is a mobile client using the HTTP header User-Agent.

If the client is mobile, it will return HTTP 302 with the Location header equal to our deep link.
The request and response are something like this:

GET /testing/1234568 HTTP/1.1
Host: myapp.com
Accept: */*
User-Agent: Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36


HTTP/1.1 302
Location: myapp://home/?abc=xxx&bcd=yyy
Content-Length: 0

This service can work perfectly in iOS, the user is redirected to our application after the user click the link.

However, for Android, it does not work. The user cannot redirect to our application after clicking the link. It still stays in a blank page.

I have tested to use a html with javascript like below:

<html>
<head>
  <script  type="text/javascript">
    window.onload = function(){ 
      window.location="myapp://home/?abc=xxx&bcd=yyy";
    };
  </script>
</head>
</html>

Android user can successfully redirect back to the application.
However, for some reason, I cannot return html in my API service.
Are there any ways to redirect the user back to the mobile application using HTTP 302 in Android?

like image 944
paddy Avatar asked Apr 16 '18 12:04

paddy


1 Answers

I believe your issue may be caused by the specific browser behavior. On Android, Chrome does not handle URI schemes the same way as the Android browser. My inclination is that you are using Chrome and should be using Chrome Intents. Essentially, in Chrome you should be using a URI scheme formatted like this:

intent://<optional path>#Intent;scheme=<URI scheme>;package=<package>;S.browser_fallback_url=<optional encoded fallback URL>;end

URI scheme [required]: This is the same URI scheme you were using above

App package name [required]: This is the package name of the app, as configured for the project.

URI path [optional]: If you want to pass in any path for routing

Fallback URL [optional]: This is an optional field where you can specify a URL encoded website URL to fallback to if the app is not installed. The default option if not specified is to open the Play Store app page. If you don’t use this variable, just remove the whole ‘S.browser_fallback_url=’ part of the intent string.

Another option is to just use Branch for your deep linking. They already cover all of these edge cases as they update and change.

like image 133
clayjones94 Avatar answered Oct 17 '22 16:10

clayjones94