在android开发过程中,我们会遇到要检查一个已知包名的android软件是否已经安装,通过以下代码即可实现判断:
1 PackageInfo packageInfo;
2 try {
3 packageInfo = this.getPackageManager().getPackageInfo(packageName, 0);
4
5 } catch (NameNotFoundException e) {
6 packageInfo = null;
7 e.printStackTrace();
8 }
9 if(packageInfo == null) {
10 System.out.println("not installed");
11 } else {
12 System.out.println("is installed");
13 }