之前做一个app,需要列出手机中安装的所有包,包括系统apps,但是又需要过滤输入法,于是后来找到这种方法来判断输入法。
public static boolean isInputMethodApp(Context context, String strPkgName) { PackageManager pkm = context.getPackageManager(); boolean bIsIME = false; PackageInfo pkgInfo; try { pkgInfo = pkm.getPackageInfo(strPkgName, PackageManager.GET_SERVICES); ServiceInfo[] servicesInfos = pkgInfo.services; if(null != servicesInfos){ for (int i = 0; i < servicesInfos.length; i++) { ServiceInfo sInfo = servicesInfos[i]; if(null != sInfo.permission && sInfo.permission.equals("android.permission.BIND_INPUT_METHOD")){ Log.i("isInputMethodApp ", strPkgName); bIsIME = true; break; }; } } } catch (NameNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return bIsIME; }
时间: 2024-11-12 02:46:02