Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass parameters to android Intent in new scheme on chrome?

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.

like image 858
user2418024 Avatar asked May 24 '13 15:05

user2418024


People also ask

What are chrome intents?

Chrome intents are the deep linking replacement for URI schemes on the Android device within the Chrome browser. Instead of assigning window. location or an iframe. src to the URI scheme, in Chrome, you'll need to use their intent string as defined in this document.

What is intent URL?

In this way, an Intent is like the dual of a hyperlink. With a hyperlink, the source page specifies the exact URL to be navigated to. With an Intent, the source page specifies the nature of the task to be done, and the user can select any of a number of applications to be used to complete the task.

How do you intent a URL?

This example demonstrates how do I send an Intent to browser to open specific URL in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is Android intent category browsable?

Include the BROWSABLE category. It is required in order for the intent filter to be accessible from a web browser. Without it, clicking a link in a browser cannot resolve to your app. Also include the DEFAULT category. This allows your app to respond to implicit intents.


2 Answers

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.

like image 84
ojovirtual Avatar answered Sep 23 '22 20:09

ojovirtual


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 
like image 34
AlexD Avatar answered Sep 22 '22 20:09

AlexD