How to determine if an application is installed on an Android device on a web page

Here is the situation:

I have a webpage that should check JavaScript if my application is already installed on the Android device it is running in.

If the application is installed, the page will show a link (with a custom protocol) for launching the application, otherwise the page should show a link to the Android market.

I can manage links to the application and to the market. The only remaining step is to detect the presence of the application on the device from JavaScript code (or, perhaps, an attempt to catch a possible error of an unsupported protocol as a reference to a non-existing application).

When I

  • click link online using
  • my user application protocol and
  • the application is not yet installed on the device

I see that the Android environment is generating an error like "protocol is not supported." Unfortunately, I can’t fix this error in the JavaScript code to redirect the user to the Android market.

I think that both direct detection and error detection are valid methods, if they exist at all.

Any ideas how I can do this?

Thanks for the help.

+5
source share
3 answers

Do not use your own protocol.

Instead, configure yours <intent-filter>to look at a well-known URL (for example, set the scheme, host, and path). This URL should point to the page where the “download application” instructions are.

, URL- - , , , -, .

+3

, :

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1;
if(isAndroid) { // if is android
    // your app address for local
    var ifrSrc = 'intent://example.com#Intent;scheme=my_scheme;action=android.intent.action.VIEW;end';
    var ifr = document.createElement('iframe');
    ifr.src = ifrSrc ;
    ifr.onload = function() { // if app is not installed, then will go this function
        window.location = 'http://your.app_download_page.com';
    };
    ifr.style.display = 'none';
    document.body.appendChild(ifr);

    setTimeout(function(){
        document.body.removeChild(ifr); // remove the iframe element
    }, 1000);
} else { // if is not android
    window.location = 'http://google.com';
}

, -, , .

+2

iframe, src url , -, . iframe invisble, frameborder = "0", width height = 0;

0

All Articles