NiTiN NiTiN - 3 months ago 26
Android Question

Invoke android application from browser

I have been trying to invoke my application from browser on android 3.1 (Honeycomb)
These are the links I tried, but none of these worked:

<a href="com.nk.myapp://movieid=95319">click me 1</a>

<a href="intent:#Intent;action=com.nk.myapp.detail;end">click me 2</a>

<a href=intent:#Intent;action=com.nk.myapp.detail;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;package=com.nk.myapp;end>click me 3</a>


For 1st and 2nd url, it gives "Webpage not available".

For 3rd one, it shows Apps-market with search: pname:com.nk.myapp --> "No Result found".

Application is still in development, so its not in the market yet.

This is how my manifest file looks like:

<activity
android:label="@string/app_name"
android:launchMode="singleTop"
android:name=".MainActivity"
android:screenOrientation="landscape" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="com.nk.myapp.action.DIALOG" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".WebViewActivity"
android:screenOrientation="landscape" >
<intent-filter>
<data android:scheme="com.nk.myapp" />
<action android:name="com.nk.myapp.detail" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>


Let me know if you find what I am doing wrong.

Answer

Here is Another way to do it:

To find out uri, this is what I added in Test Apk:

Intent i = new Intent();
i.setAction("com.appname.NK_CUSTOM_ACTION");
i.putExtra("movie_id", "123456");
Log.e("IntentTest", i.toUri(Intent.URI_INTENT_SCHEME));

Which produces this string:

intent:#Intent;action=com.appname.NK_CUSTOM_ACTION;S.movie_id=123456;end

Html page has this link:

<a href="intent:#Intent;action=com.appname.NK_CUSTOM_ACTION;S.movie_id=123456;end">click to load</a>

And, change manifest file to

<activity
    android:name=".TestActivity"
    android:screenOrientation="sensorLandscape" >
    <intent-filter>
        <action android:name="com.appname.NK_CUSTOM_ACTION" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
</activity>

In TestActivity, you get movie_id in code below:

Intent intent = getIntent();
String data = intent.getStringExtra("movie_id");