How to check whether an application is installed in your ANDROID Phone?

This sample code comes handy when you have to check that an application is already installed in your ANDROID Phone.
Call the below function appInstalledOrNot() with the package name of the app installed on the ANDROID Device as a string parameter.

This function returns true if the app is installed otherwise returns false.

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;

public class Example extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.main);
    	//Put the package name here...
    	boolean installed  =   appInstalledOrNot("com.Ch.Example.pack");
    	if(installed)
    	{
    	          System.out.println("App already installed om your phone");
    	}
    	else
    	{
    		System.out.println("App is not installed om your phone");
    	}
    }
    private boolean appInstalledOrNot(String uri)
    {
        PackageManager pm = getPackageManager();
        boolean app_installed = false;
        try
        {
               pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
               app_installed = true;
        }
        catch (PackageManager.NameNotFoundException e)
        {
               app_installed = false;
        }
        return app_installed ;
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>