Tuesday, August 27, 2013

Android: launch app via URI link from web browser

Android: steps for launch app via URI link from web browser

edit launcher.html
..
<a href="myscheme://?host=my_app_server&port=9000&servername=StubServer">MyApp@MyServer</a>
..

Android project:
edit AndroidManifest.xml, add activity's intent-filter as below:

<application android:icon="@drawable/ventyx_icon" android:label="@string/app_name"
        android:debuggable="true" android:logo="@drawable/splash">
 <activity android:name="MyMobile" android:label="@string/app_name" ....>



     <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="myscheme" />   << all lowercase
     </intent-filter>           
  </activity>
....


The above code will launch "MyMobile" application if the scheme is myscheme, e.g., "myscheme://"

For better control the launcher URL, we can apply more intent filter options as 

<data android:scheme="myscheme" android:host="myapp.dev.com" android:pathPrefix="/mobile" />
In this case, MyMobile application will be launched by URL like below:
<a href="myscheme://myapp.dev.com/mobile?other_query_params">

No comments:

Post a Comment