Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?

So I want to create an Android app so it would be registered somewhere in android OS (or just would start on system start) and when phone user clicks on special button on a web page inside a web browser a la:

 <a href="myapp://mysettings">Foo</a>  

my app would pop up and run using the params sent in that URL.

So how do I do such thing?

I need a tutorial with code!

like image 767
Rella Avatar asked Mar 12 '10 02:03

Rella


1 Answers

First, to be able to start your app from link with custom scheme 'myapp' in browser / mail, set intent filter as follows.

<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="myapp"/>  </intent-filter> 

and to parse queries in your link myapp://someaction/?var=str&varr=string
(the code is over simplified and has no error checking.)

Intent intent = getIntent(); // check if this intent is started via custom scheme link if (Intent.ACTION_VIEW.equals(intent.getAction())) {   Uri uri = intent.getData();   // may be some test here with your custom uri   String var = uri.getQueryParameter("var"); // "str" is set   String varr = uri.getQueryParameter("varr"); // "string" is set } 

[edit] if you use custom scheme to launch your app, one of the problem is that: The WebView in another apps may not understand your custom scheme. This could lead to show 404 page for those browser for the link with custom scheme.

like image 169
9re Avatar answered Sep 18 '22 13:09

9re