Android programs a way to determine if a program is installed on your phone
- 2020-10-31 21:59:37
- OfStack
This article illustrates how Android programming can determine if a program is installed on your phone. To share for your reference, the details are as follows:
1. Get the package name of the program first
This is connected to the ADB, and you can see it by looking at the logcat. For example: the package name of QQ client is ES9en.tencent.mobileqq.
2. Then PackageManager determines whether the package program exists
private boolean isPkgInstalled(String pkgName) {
PackageInfo packageInfo = null;
try {
packageInfo = this.getPackageManager().getPackageInfo(pkgName, 0);
} catch (NameNotFoundException e) {
packageInfo = null;
e.printStackTrace();
}
if (packageInfo == null) {
return false;
} else {
return true;
}
I hope this article has been helpful in Android programming.