查询android系统中是否存在某个APK
在某个Activity里,查询android系统中是否存在某个APK
String currentIme = "com.android.inputmethod.latin/.LatinIME";
ComponentName component = ComponentName.unflattenFromString(currentIme);
//打印component.toString():ComponentInfo{com.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME}
Log.i(TAG,"component.toString():" + component.toString());
Intent imeIntent = new Intent(component.getPackageName() + ".tutorial");
//打印com.android.inputmethod.latin.tutorial
Log.i(TAG,"imeIntent.toURI():" + imeIntent.toURI());
PackageManager pm = getPackageManager();
//返回系统中全部符合action为:com.android.inputmethod.latin.tutorial的apk
List<ResolveInfo> tutorials = pm.queryIntentActivities(imeIntent, 0);
if(tutorials == null || tutorials.isEmpty()) {
Log.i(TAG,"不存在:" + imeIntent.toURI());
}
else
{
Log.i(TAG,"存在,共有:" + tutorials.size());
}
参考:
packages\apps\Settings\src\com\android\settings\DeviceInfoSettings.java