public boolean checkPrograme(String packName,String actvityName) {
boolean flag = false;
PackageManager manager = getPackageManager();
// 只查找启动方式为LAUNCHER并且是ACTION_MAIN的APP
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// 根据Intent值查询这样的app
final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
for(ResolveInfo app:apps){
//该应用的包名和主Activity
String pkg = app.activityInfo.packageName;
String cls = app.activityInfo.name;
if(pkg.equals(packName) || cls.equals(actvityName)){
try {
info = manager.getPackageInfo(pkg, 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
String mVersonName = info.versionName;
int versionCode = info.versionCode;
Log.v("TAG", "==========mVersonName :"+mVersonName);
break;
}
Log.v("TAG", "pkg :"+pkg);
Log.v("TAG", "cls :"+cls);
}
return flag;
}
标签:String,app,程序,TAG,Intent,pkg,android,安装,cls
From: https://blog.51cto.com/u_3124497/6914304