Learn how to check if an application is installed on the device on android cordova.

If you need to verify if an app is installed on an android device, and you want to achieve it quickly, you're in the right place. The Cordova App Installed plugin allow you to verify with a couple of lines if an application is installed on the device with its package name.

Note: this solution is only available for cordova Android Platform (If you need support for iOS go to the end of the article on Open app).

Requirements

Download the Cordova App Installed plugin (written by Our Code World) executing the following command on your command line :

cordova plugin add https://github.com/ourcodeworld/cordova-ourcodeworld-appinstalled.git

Read more about the plugin on its homepage here. After the installation you'll be able to use the OurCodeWorldappinstalled variable after the deviceready event of cordova.

Verify if app is installed

To verify if an application is installed on the device, use the check method which expects the package name of the app as first parameter.

// Open facebook if installed
OurCodeWorldappinstalled.check("com.facebook.katana",{
    success: function(app){
        console.info("The app is installed");
        // Open the app if you want (optional)
        app.open();
    },
    fail: function(){
        console.info("The app is NOT installed");
    },
    error: function(){
        console.info("An error ocurred while trying to check if the app exists.");
    }
});

As you can see, on the success callback, the function receives as first parameter an "instance" of the app which can be used to open it directly without use the open method twice.

Open app

To open an application use the open method. This method offers too the use of callbacks (success and error).

OurCodeWorldappinstalled.open("com.ourcodeworld.ourcodeeditorfree",{
    success: function(){
        console.info("The app has been started");
    },
    error: function(err){
        console.info("The app cannot be started, maybe doesn't exists or an error ocurred");
    }
});

If you need a deep customization of how the app should be started, it would be better if you use the following plugin instead.

StartApp plugin (available for iOS and Android). This plugin can be downloaded using the following command on your command prompt :

cordova plugin add com.lampa.startapp

Read more about this plugin here and all the methods and possibilities that it offers here.


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors