android 通过包名获取APP的SDK版本 判断APP是否为系统应用
android 通过包名获取APP的SDK版本
public int getTargetSdkVersion(final String packageName) { try { PackageManager mPackageManager = context.getPackageManager(); ApplicationInfo info = mPackageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA); return info.targetSdkVersion; } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Cannot find package: " + packageName, e); } return SDK_NULL; }
判断APP是否为系统应用
private boolean isSystemApp(PackageManager packageManager, String[] packageNames) { for (String packageName : packageNames) { try { final ApplicationInfo info = packageManager.getApplicationInfo(packageName,0 /* flags */); if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { return true; } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Package not found: " + packageName, e); } } return false; }
版权声明:如无特殊标注,文章均为本站原创,转载时请以链接形式注明文章出处。
评论