Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Android app through deep link if it's installed or fall back to web if not installed

I'm trying to create a web page that automatically opens an Android app but only if app is installed. In case it's not it should redirect to another web page.

The app is already in production and is properly handling deep links like example://content?id=42. The format of the link could not be changed.

What I've already tried

1) Redirects and timeout:

window.location.replace('example://content?id=42');
setTimeout(function() {
    window.location.replace = 'http://example.com/content?id=42';
}, 500);

Works fine for iOS but for Android it redirects to example:// immediately and thus gives me ERR_UNKNOWN_URL_SCHEME. Seems to be no go for Android.

2) iframe approach. Impossible in rencent Chrome versions. Also doesn't seem to work in Samsung browser.

3) Intents with S.browser_fallback_url. Works well but in Chrome only. Doesn't work in Opera and Samsung browser... most probably nowhere else but Chrome 25+.

like image 439
Sam Dark Avatar asked Aug 31 '15 15:08

Sam Dark


People also ask

What happens with a deep link if the app is not installed?

The deep link directly takes them to the relevant content inside the app. But if they don't have the app installed, it instead takes them to the right app store and asks them to download the app to view the content. Simply put, the deep linking here is 'deferred' until the application is installed by the user.

Can I open Android app from URL?

You achieve this by Deep linking in your app. First of all you need to add intent filters for incoming links. Specify the ACTION_VIEW intent action so that the intent filter can be reached from Google Search. Add one or more tags, each of which represents a URI format that resolves to the activity.

How do I redirect Google Play apps not installed?

playmarket=true before processing the url. on your server check, if ? playmarket=true is present, then just redirect to your app's page in google play.


1 Answers

use http://example.com/content?id=42 as the link and add the intent filter to your activity in manifest

<intent-filter>
    <data android:scheme="http" android:host="example.com" />
    ...
</intent-filter>

However, a list of app registered, e.g. browsers, will show up when the link is first accessed on the machine.

like image 65
Derek Fung Avatar answered Sep 28 '22 07:09

Derek Fung