判断是否为系统应用的几种方法[整理]

原文链接: http://www.lepeng.net/blogger/?p=306

 

1. if(new File("/data/app/" + packageInfo.packageName + ".apk").exists())

2. packageInfo.versionName != null && packageInfo.applicationInfo.uid > 10000

3. if((packageInfo.applicationInfo.flags& ApplicationInfo.FLAG_SYSTEM) != 0)

 

* 经测试,最好使用第3个方法,另外两个不大准。


补充:: 示例代码>>

public static boolean isSystemApplication(Context context, String packageName){
    	PackageManager manager = context.getPackageManager();
        try {
			PackageInfo packageInfo = manager.getPackageInfo(packageName, PackageManager.GET_CONFIGURATIONS);
			// 1
			if(new File("/data/app/"+packageInfo.packageName+".apk").exists()){
				return true;
			}
			// 2
			if(packageInfo.versionName!=null && packageInfo.applicationInfo.uid>10000){
				return true;
			}
			// 3
			if((packageInfo.applicationInfo.flags & android.content.pm.ApplicationInfo.FLAG_SYSTEM)!=0){
				return true;
			}
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return false;
    }

你可能感兴趣的:(android,.net)