26

I have a web app calling a native app on android via an iframe intent which does not work in chrome 25 according to the following....

https://developers.google.com/chrome/mobile/docs/intents

The intent was structured like the following....

app://Requesttype=Testing&Type=123&tn=0000000000

In the new intent:// scheme how would I go about passing the parameters listed after app:// to the native application? I haven't been able to find an example.

2
  • there is clearly something missing in the doc, however the link to the source contains some explanation. apparently it's about code.google.com/p/android-source-browsing/source/browse/core/… a type, a dot, the key, '=', the value, and a semi-colon (rather than a &)
    – njzk2
    May 24, 2013 at 15:44
  • @njzk2 it is in the docs, you have it in the Path section.
    – Kinlan
    May 30, 2013 at 11:57

4 Answers 4

64

With the new scheme, you can pass arguments as extras to the App, but you must encode the URI as follows:

<a href="intent://whatever/#Intent;scheme=myapp;package=com.what.ever.myapp;S.myextra=mystring;end">Do Whatever</a>

This will pass an extra String called "myextra" with the value "mystring". Having a look at the Android Code we can see how the extra parameters need to be coded. The "S" at the beginning of the "myextra" parameter defines it as a String. Other types can be:

String => 'S'
Boolean =>'B'
Byte => 'b'
Character => 'c'
Double => 'd'
Float => 'f'
Integer => 'i'
Long => 'l'
Short => 's'

For example, if we want to pass two extra parameters, an Integer and a String, we can do this:

<a href="intent://whatever/#Intent;scheme=myapp;package=com.what.ever.myapp;S.name=Perico%20de%20los%20Palotes;i.age=35;end">Do Whatever</a>

Note that you'll need to url-encode all the parameters.

In your Android app, you'll need to accept those extras. In the "onCreate" event of your Activity:

Bundle parametros = getIntent().getExtras();
if (extras != null){
    String name = extras.getString("name");
    Integer age = extras.getInt("age");

    if (name!=null && age!=null)
    {
       //do whatever you have to
       //...
    }
}else{
     //no extras, get over it!!
}

And, of course, add the filter android.intent.category.BROWSABLE in your manifest as shown in this link.

5
  • 4
    Thank you! This is the first good explanation I've seen for how to add the extras to the intent uri.
    – Nick White
    Jun 30, 2014 at 18:57
  • 4
    Thank you for the info. Some additional notes: you can just use intent:#Intent;...;end, no need for whatever. The activity needs to have BROWSABLE and DEFAULT categories in intent filter. component= is actually ignored, use package= to specify your package.
    – domen
    Aug 14, 2014 at 10:56
  • I found a fix check my answer above
    – Sid
    Aug 18, 2015 at 15:03
  • 1
    Do you know what can i use for serializable extra? Oct 20, 2016 at 13:13
  • How about the encoding? It seems like android intents sent from the webapp are encoded in UTF-8, so if I send japanse words like 買い物 it gets encoded into %E8%B2%B7%E3%81%84%E7%89%A9. How can I ensure I receive the same word without encoding and decoding it?
    – dryleaf
    Jan 24, 2019 at 0:18
8

For the scheme URL:

appname://RequestType/?Type=123&tn=0000000000

You would want to map to an intent URL of:

intent://RequestType/?Type=123&tn=0000000000#Intent;scheme=appname;package=com.example.appname;end
8
  • where is the link to the other types?
    – Lena Bru
    Dec 12, 2013 at 18:29
  • The types, in fact, don't matter here. I've updated my answer for correctness.
    – AlexD
    Dec 21, 2013 at 1:26
  • How do i refer to the play store if the app is not installed?
    – Lena Bru
    Dec 22, 2013 at 8:09
  • That should happen automatically
    – AlexD
    Jan 4, 2014 at 0:05
  • it happens only if i add "package=mypackagename" otherwise it doesnt, and i was missing that
    – Lena Bru
    Jan 4, 2014 at 16:24
5

You can no longer use an iframe and custom protocol to open a native app.

You can however use the existing intent:// syntax to launch and intent and pass it data, it has the added benefit of taking the user to the Play store if it is not installed.

You either encode the data in the "path" part of the syntax as documented so you could have intent://play/?a=1#Intent;......;end; or you could encode it as an Extra.

4
  • i can't find the part relative to path syntax in the documentation. all details i found are in the source, around line 3720. where did you find a more detailed documentation?
    – njzk2
    May 30, 2013 at 12:38
  • it says "HOST/URI-path // Optional host", this is the place where the data is passed through.
    – Kinlan
    May 30, 2013 at 16:04
  • It's pretty much the same as what was asked in the question (query parameters) - but the intent syntax is a little obscure.
    – Kinlan
    May 30, 2013 at 16:28
  • The link in the answer is dead. I think this is the updated one: developer.chrome.com/multidevice/android/intents
    – Karu
    May 5, 2015 at 2:09
4

Intents are not working after 4.4.4, So this is what i am doing for my app.

created custom scheme to launch my activity in the AndroidManifest.xml with the following intent filter

1)

 <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:scheme="<<YOUR UNIQUE SCHEME(I SUGGEST YOUR PACKAGE NAME)"/>
</intent-filter>

2) Construct market url with fallback url which opens your app through custom scheme created above.

market://details?id=<<your app package from AndroidManifest.xml>>&url=<<your app custom scheme from AndroidManifest.xml>>://yourdomain.com?encoded(p1=v1&p2=v2....etc)

this opens the store if your app is not installed, and opens the app with the intent data if the app is already installed, with your decoded parameters.

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.