Android open links in browser

Android Intents with Chrome

Published on Friday, February 28, 2014

A little known feature in Android lets you launch apps directly from a web page via an Android Intent. One scenario is launching an app when the user lands on a page, which you can achieve by embedding an iframe in the page with a custom URI-scheme set as the src , as follows: . This works in the Chrome for Android browser, version 18 and earlier. It also works in the Android browser, of course.

The functionality has changed slightly in Chrome for Android, versions 25 and later. It is no longer possible to launch an Android app by setting an iframe’s src attribute. For example, navigating an iframe to a URI with a custom scheme such as paulsawesomeapp:// will not work even if the user has the appropriate app installed. Instead, you should implement a user gesture to launch the app via a custom scheme, or use the «intent:» syntax described in this article.

# Syntax

The best practice is to construct an intent anchor and embed that into the page so the user can launch the app. This gives you a lot more flexibility in controlling how apps are launched, including the ability to pass extra information into the app via Intent Extras.

The basic syntax for an intent-based URI is as follows:

See the Android source for parsing details.

Also, you may choose to specify fallback URL by adding the following string extra:

When an intent could not be resolved, or an external application could not be launched, then the user will be redirected to the fallback URL if it was given.

Some example cases where Chrome does not launch an external application are as follows:

  • The intent could not be resolved, i.e., no app can handle the intent.
  • JavaScript timer tried to open an application without user gesture.

Note that S. is a way to define string extras. S.browser_fallback_url was chosen for backward compatibility, but the target app won’t see browser_fallback_url value as Chrome removes it.

# Examples

Here’s an intent that launches the Zxing barcode scanner app. It follows the syntax thus:

To launch the Zxing barcode scanner app, you encode your href on the anchor as follows:

See the Android Zxing Manifest, which defines the package and the host.

Also, if fallback URL is specified, the full URL will look like this:

Now the URL will get you to zxing.org if the app could not be found, or the link was triggered from JavaScript without user gesture (or for other cases where we don’t launch an external application.)

# Considerations

If the activity you invoke via an intent contains extras, you can include these as well.

Only activities that have the category filter, android.intent.category.BROWSABLE are able to be invoked using this method as it indicates that the application is safe to open from the Browser.

# See also

And Chrome doesn’t launch an external app for a given Intent URI in the following cases.

  • When the Intent URI is redirected from a typed in URL.
  • When the Intent URI is initiated without user gesture.

Last updated: Friday, February 28, 2014 • Improve article

Читайте также:  Аудиоплеер с тегами для андроид

Источник

How to Open an Android App from the Browser

Alex Austin

January 8th, 2018

Opening an installed app from a browser is often referred to as “deep linking”, and with this guide you’ll learn how to deep link into your Android app for yourself. We’ll focus exclusively on how to trigger an app open from a website page, rather than from the click of a link inside other apps. For a more detailed look at all of the different deep linking standards required for complete Android coverage, please see our Android deep linking series: Part 1 , Part 2 , Part 3 , and Part 4 .

Android is, by far, one of the most fragmented platforms that developers have ever had to manage, due to Google’s decision to force device manufacturers to be responsible for porting the OS, which requires backwards compatibility and support of a multitude of devices. In this ecosystem, we, the app developers, are left to pick up the pieces. Deep linking on Android is unfortunately no different—over the years, we’ve seen a plethora of technical requirements that must be used depending on the circumstance and context of the user.

Note that Branch will implement all of this complexity for you, host the deep links, and even give you robust analytics behind clicks, app opens, and down funnel events. You can play around with Branch links for free by signing up here . We highly recommend using our tools instead of trying to rebuild them from scratch, since we give them all away for free.

Overview of Changes

There are two places where changes will need to be made in order to successfully open your Android app: your website and your Android app. You can find the details of each change in the corresponding sections below.

Adding Support for URI Schemes to Your App

A URI scheme can be any string without special characters, such as http , pinterest , fb or myapp . Once registered, if you append :// to the end (e.g. pinterest://) and click this link, the Pinterest app will open up. If the Pinterest app is not installed, you’ll see a ‘Page Not Found’ error.

It is simple to configure your app for a URI scheme. To start, you need to pick an Activity within your app that you’d like to open when the URI scheme is triggered, and register an intent filter for it. Add the following code within the tag within your manifest that corresponds to the Activity you want to open.

You can change your_uri_scheme to the URI scheme that you’d like. Ideally, you want this to be unique. If it overlaps with another app’s URI scheme, the user will see an Android chooser when clicking on the link. You see this often when you have multiple browsers installed, as they all register for the http URI.

Next, you’ll want to confirm that your app was opened from the URI scheme. To handle the deep link in the app, you simply need to grab the intent data string in the Activity that was opened via the click. Below is an example:

From here, you’ll need to do string parsing to read the values appended the URI scheme that will be very specific to your use case and implementation.

Adding Javascript to Your Website to Open Your App

Now that your Android app is ready to be triggered from a URI scheme, the next part is simple. You merely need to add some Javascript to your website that will auto trigger your app open. The function below, triggerAppOpen , will attempt to open your app’s URI scheme once you replace your_uri_scheme with the one you added in the manifest above.

You could call triggerAppOpen into window.onload if you wanted to do it on page load, or you could make it the onclick of a link somewhere on your site. Either works and the you’ll get the intended results.

Читайте также:  Автоответчик робот для андроида

Android is incredibly complicated, and there are edge cases everywhere. You’ll think everything is going well until you get that one user complaining that his links aren’t working on Facebook while running Android 4.4.4. That’s why you should use a tool like Branch—to save you this nightmare and ensure that your links work everywhere. Be sure to request a Branch demo if you’re interested in learning more.

Источник

Android App Linking

The ultimate developer guide to Android application linking methods

The main objectives of this guide are to explore the most common deeplinking methods available on Android and evaluate their pros and cons.
The source code of the AppLinks Android app is available on the corresponding GitHub repository.

Method Link App not installed Offline Referrer Deeplink Deferred deeplink
Web url Test ✔️ ✔️
App Links Test ✔️ ✔️
Custom scheme Test ✔️ ✔️
Intent scheme Test ✔️ ✔️ ✔️ ✔️
App scheme Test ✔️ ✔️ ✔️ ✔️
Firebase Dynamic Links Test ✔️ ✔️ ✔️
Play Store url Test ✔️ ✔️ ✔️ ✔️
Market scheme Test ✔️ ✔️ ✔️ ✔️ ✔️

Web url

http://smarquis.fr/action?key=value#data

Android

Uri Value
scheme http
host smarquis.fr
path /action
query ?key=value
fragment data

Features

Feature ✔️ / ❌
App not installed
Offline ✔️
Referrer
Deeplink ✔️
Deferred deeplink

Pros and Cons

  • Initial disambiguation dialog
  • Doesn’t work on the same domain
  • Some (in-app) browsers might directly handle these links and prevent the app to launch

https://smarquis.fr/action?key=value#data

A JSON verification file needs to be available at https://smarquis.fr/.well-known/assetlinks.json containing the application’s package name and keystore fingerprint

To test an existing statement file, you can use the official Statement List Generator and Tester tool.

During app install/update, an Android service will verify if the App Links configuration complies with the server side assetlinks.json file.
The results will be sent to logcat, with these tags: IntentFilterIntentSvc and SingleHostAsyncVerifier

Click to see logcat content

Valid App Links configuration

Invalid App Links configuration (missing or malformed assetlinks.json file, missing package_name or sha256_cert_fingerprints )

Android

Same as Web url but with https only and android:autoVerify=»true» attribute.

Uri Value
scheme https
host smarquis.fr
path /action
query ?key=value
fragment data

Features

Feature ✔️ / ❌
App not installed
Offline ✔️
Referrer
Deeplink ✔️
Deferred deeplink

Pros and Cons

  • No more disambiguation dialog
  • No potential app hijacking
  • Doesn’t work on the same domain
  • Some (in-app) browsers might directly handle these links and prevent the app to launch

Custom scheme

link://smarquis.fr/action?key=value#data

Android

Uri Value
scheme link
host smarquis.fr
path /action
query ?key=value
fragment data

Features

Feature ✔️ / ❌
App not installed
Offline ✔️
Referrer
Deeplink ✔️
Deferred deeplink

Pros and Cons

  • Some browser doesn’t handle non-http links

Intent scheme

intent://smarquis.fr/action?key=value#data#Intent;scheme=link;package=fr.smarquis.applinks;S.key=value;S.market_referrer=my%20referrer%20data;end

Extra parameters can be added to the link and will be transfered as extras Bundle in the Intent :

  • String: S.key=value
  • Boolean: B.key=value
  • Integer: i.key=value
  • Long: l.key=value
  • Float: f.key=value
  • S.browser_fallback_url is the fallback URL if the corresponding link doesn’t work of if app isn’t available (will be removed from the Intent ).
  • S.market_referrer will trigger a com.android.vending.INSTALL_REFERRER Broadcast once the app is installed.

Android

The url will be rewritten by the parseUri() method from the Android source code.
The new url will be link://smarquis.fr/action?key=value#data

And will contain additional parameters in the Intent .

Uri Value
scheme link
host smarquis.fr
path /action
query ?key=value
fragment data
Extra Value
key value
market_referrer my referrer data
Referrer
my referrer data

Features

Feature ✔️ / ❌
App not installed ✔️
Offline ✔️
Referrer ✔️
Deeplink ✔️
Deferred deeplink

Pros and Cons

  • Some browser doesn’t handle non-http links

App scheme

android-app://fr.smarquis.applinks/https/smarquis.fr/action?key=value#data#Intent;S.key=value;S.market_referrer=my%20referrer%20data;end

Extra parameters can be added to the link and will be transfered as extras Bundle in the Intent :

  • String: S.key=value
  • Boolean: B.key=value
  • Integer: i.key=value
  • Long: l.key=value
  • Float: f.key=value
  • S.market_referrer will trigger a com.android.vending.INSTALL_REFERRER Broadcast once the app is installed.

Android

The url will be rewritten by the parseUri() method from the Android source code.
The new url will be https://smarquis.fr/action?key=value#data

And will contain additional parameters in the Intent .

Uri Value
scheme https
host smarquis.fr
path /action
query ?key=value
fragment data
Extra Value
key value
market_referrer my referrer data
Referrer
my referrer data

Features

Feature ✔️ / ❌
App not installed ✔️
Offline ✔️
Referrer ✔️
Deeplink ✔️
Deferred deeplink

Pros and Cons

  • Some browser doesn’t handle non-http links

https://mr7f2.app.goo.gl/Tbeh

Create the link from the Firebase console.

Android

Same requirements as App Links.
And add the Firebase Dynamic Links dependency in the app-level build.gradle file:

Then in your Activity ‘s onCreate method, use this code to get the link if the user came from a Firebase Dynamic Link:

Uri Value
scheme https
host smarquis.fr
path /action
query ?key=value
fragment data

Features

Feature ✔️ / ❌
App not installed ✔️
Offline
Referrer
Deeplink ✔️
Deferred deeplink ✔️

Pros and Cons

  • Ugly progress dialog when fetching link data

Play Store url

https://play.google.com/store/apps/details?id=fr.smarquis.applinks&url=link%3A%2F%2Fsmarquis.fr%2Faction%3Fkey%3Dvalue%23data&referrer=my%20referrer%20data

Very similar to the Market scheme.

This url contains additional query parameters that will be handled by the Play Store app:

  • url is the forwarded url
  • referrer will trigger a com.android.vending.INSTALL_REFERRER Broadcast once the app is installed.

Android

The url will be rewritten by the Play Store to link://smarquis.fr/action?key=value#data

Uri available in deferred deeplink only

Uri Value
scheme link
host smarquis.fr
path /action
query ?key=value
fragment data
Referrer
my referrer data

Features

Feature ✔️ / ❌
App not installed ✔️
Offline ✔️
Referrer ✔️
Deeplink
Deferred deeplink ✔️

Pros and Cons

  • Some (in-app) browsers might directly handle these links and prevent the Play Store app to launch
  • When app is installed, it still opens the Play Store app and completely ignores the deeplink
  • Changes the «Open» button in Play Store to «Continue»
  • Triggers a notification with «Tap to continue»

Market scheme

market://details?id=fr.smarquis.applinks&url=link%3A%2F%2Fsmarquis.fr%2Faction%3Fkey%3Dvalue%23data&referrer=my%20referrer%20data

This url contains additional query parameters that will be handled by the Play Store app:

  • url is the forwarded url
  • referrer will trigger a com.android.vending.INSTALL_REFERRER Broadcast once the app is installed.

Android

The url will be rewritten by the Play Store to link://smarquis.fr/action?key=value#data

Uri Value
scheme link
host smarquis.fr
path /action
query ?key=value
fragment data
Referrer
my referrer data

Features

Feature ✔️ / ❌
App not installed ✔️
Offline ✔️
Referrer ✔️
Deeplink ✔️
Deferred deeplink ✔️

Pros and Cons

  • Changes the «Open» button in Play Store to «Continue»
  • Triggers a notification with «Tap to continue»

Referrer Receiver

Add the Broadcast Receiver in AndroidManifest.xml

And in the Receiver’s onReceive() method, you can get the referrer value

Deeplinking

You can get the deeplink Uri in your Activity ‘s onCreate() method as well as the corresponding properties:

When using Play Store url or Market scheme or Firebase Dynamic Links methods, the regular Play Store Open button will be replaced by a Continue button.
Furthermore, a notification will be displayed with Tap to continue content.
These two actions are essential to the Deferred deeplink method as they provide the initial data to the app.

Regular Deeplink Deferred Deeplink

Url redirections

Adb Activity Manager

To try links with adb, use the Activity Manager (am) command:

Источник

Читайте также:  Android studio переопределить tostring kotlin
Оцените статью