Detect from browser if a specific application is installed in Android

You mean from JavaScript running in the browser? I think (hope) that's impossible. I wouldn't want any random website to be able to see what apps are installed.

If you want the user to install a particular app, you can provide a Market link on your website: http://developer.android.com/guide/publishing/publishing.html#marketintent

Edit: After your clarification in the comments to my answer, a more useful answer appeared below, which rightfully has more upvotes.


I have found a more useful solution. Below is the android config file:

<activity android:name="me.test.html.MainActivity" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="xxxxx"
            android:scheme="mm" />
    </intent-filter>
</activity>

Below is the html code:

<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<title>Insert title here</title>  
<script type="text/javascript">
function test2(){
    var di = document.getElementById("di");
    di.innerHTML = "app have not installed";
}
function newOpen(){//184 064 323 438
    var di = document.getElementById("di");
    di.innerHTML = "app have installed";
    var ifc = document.getElementById("ifc");
    ifc.innerHTML = "<iframe src='mm://xxxxx?a=b&c=d' onload='test2()'></iframe>";
    return false;
}
</script>
</head>  
<body>  
 <a href="#" onclick="return newOpen()">local3</a><br/> 
<div id="di"></div> 
 <div style="display:none;" id="ifc"></div>
</body>  
</html>

In this way, when the user clicks the tag, and if the device has the app installed, then it will not show a dialog to let the user choose, but instead open the app directly; and if the app hasn't been installed, then the js function "test2" will be called, therefore we know that the app has not been installed, so we can do anything in the "test2"! The benefit is that we don't need to use the standard html schema, which would show a choose dialog, and if I use the defined schema myself, the page would not been navigated to a wrong page! I am a Chinese, my English is not good, hope everyone could understand me and let's others know the resolution.


There is a way to achieve this.

You cannot detect if a particular application is installed, for security and privacy reasons. But you can do a trick to open the app if it's installed or open its Google Play page if it isn't.

To do that, you must create an intent-filter on your app's main activity, to open it when a given URL is called. Like this:

    <activity android:name=".MainActivity >
        <intent-filter>
            <data
                android:host="www.myurl.com"
                android:pathPrefix="/openmyapp"
                android:scheme="http" >
            </data>

            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity> 

Explaining: when the user navigates to http://www.myurl.com/openmyapp, if the app is installed, an intent will be created and the Activity will be shown.

But what if the user doesn't have the app installed? Then you need to create a redirect page on your http://www.myurl.com/openmyapp/index.html. When the user reaches this address, your server must redirect to market://details?id=com.your.app.package.

This way, when no Intent is created after the user navigates to http://www.myurl.com/openmyapp, the webserver will call another URL. That URL, in turn, will open Google Play on the device, directly on the app's page.

Hope it helps.

Tags:

Android