Android Intents with Chrome

You can launch apps directly from a web page on an Android device with an Android Intent. You can implement a user gesture to launch the app with a custom scheme or use the intent: syntax.

Construct an intent anchor and embed it within a page, so the user can choose to launch the app. This allows flexibility for how and when apps are launch, which means you can pass information to the app with Intent Extras.

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

intent:  
   HOST/URI-path // Optional host  
   #Intent;  
      package=\[string\];  
      action=\[string\];  
      category=\[string\];  
      component=\[string\];  
      scheme=\[string\];  
   end;

Refer to the Android source code for parsing details.

When an intent isn't resolved or an external application doesn't launch, the user can be redirected to the fallback URL. You can specify a fallback URL with an Intent Extra:

S.browser_fallback_url=[encoded_full_url]

Use S.<name> define Intent Extras. This particular extra is backwards-compatible. Chrome removes browser_fallback_url so the target app doesn't see this value.

Chrome won't launch an external application in the following cases:

  • The intent cannot be resolved. In other words, no app can handle the intent.
  • A JavaScript timer tried to open an application without a user gesture.

Examples

Here's an intent that launches the Zxing barcode scanner app:

intent:  
   //scan/  
   #Intent;  
      package=com.google.zxing.client.android;  
      scheme=zxing;  
   end;

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

  <a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end">
    Take a QR code
  </a>

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

When a fallback URL is specified, the full URL looks as follows:

   <a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;S.browser_fallback_url=http%3A%2F%2Fzxing.org;end">
    Take a QR code
  </a>

Now the URL sends users to zxing.org if the app cannot be found, the link is triggered by JavaScript without user gesture, or other cases where we don't launch an external application.

Considerations

If you invoke an Android Activity with an Intent that contains Extras, you can include these details, too.

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

Chrome won't launch an external app for a given Intent URI if:

  • The Intent URI is redirected from a typed in URL;
  • The Intent URI is initiated without user gesture.