Check if an App is Installed or not in Android Java

Android look if an app is installed or not with package name

Sometimes, we need check if a particular app is installed or not in a device, this is useful for apps such as apps that has a pro version to unlock features, key app to disable ads or just to check if an app you want already installed or not.

First, place this string above oncreate method

String packagename = "com.ztronnfbkey";

And here is the code to check if a particular app is installed or not

PackageManager packageManager = getPackageManager();
ApplicationInfo applicationInfo = null;
try {
applicationInfo = packageManager.getApplicationInfo(packagename, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (applicationInfo == null) {

//the app not installed so do some action
Toast.makeText(this, "The app not installed", Toast.LENGTH_SHORT).show();
}


return false;
} else {
//the app is installed so do some action
Toast.makeText(this, "The app is installed", Toast.LENGTH_SHORT).show();
}

 

How does this work?

This code checks for the installation status of an app by its package name that you have set in “String packagename” , if the app is found or not found, the code will execute a toast message, instead of toast, you can set an action with intent or other methods.

The code can be placed below a button action or menu item

, ,

Post navigation

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.