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 ; } }
Your method takes package name as a parameter. I want to know if we can use the application name instead?
You cannot use application name because different application can have same name.