Skip to content Skip to sidebar Skip to footer

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: Copy

Which produces this string:

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

Html page has this link:

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

And, change manifest file to

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

In TestActivity, you get movie_id in code below:

Intentintent= getIntent();
Stringdata= intent.getStringExtra("movie_id");

Solution 2:

Solved the problem while ago, just in case anyone needs it:

This is how my html page looks like (which get downloaded from browser on device):

<!DOCTYPE htmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>Andriod Sample</title><scripttype="text/javascript">functiongetQuerystring(key, default_) {
            if (default_ == null) default_ = "";
            key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regex = newRegExp("[\\?&]" + key + "=([^&#]*)");
            var qs = regex.exec(window.location.href);
            if (qs == null)
                return default_;
            elsereturn qs[1];
        }

        functioninvokeApp(xyz) {
            var id = getQuerystring('id');
            var contentType = getQuerystring('contentType');
            var url = "myAppSceme://movie?id=" + id ;    
            document.getElementById('ref').href = url;                
        }

    </script></head><body><div><ahref="#"id="ref"onclick="invokeApp(this);" >click me!</a></div></body></html>

And my Manifest file looks like this:

<activityandroid:name=".DetailActivity"android:screenOrientation="sensorLandscape" ><intent-filter ><dataandroid:scheme="myAppSceme" /><actionandroid:name="android.intent.action.VIEW" /><categoryandroid:name="android.intent.category.BROWSABLE" /><categoryandroid:name="android.intent.category.DEFAULT" /></intent-filter></activity>

Code in DetailActivity:

String id = getIntent().getDataString().replace("myAppSceme://movie?id=", "");

Post a Comment for "Invoke Android Application From Browser"