android 判断应用程序是系统程序还是用户程序

直接上代码:

AppInfo.java

<span style="font-size:18px;">package com.example.packages;

public class AppInfo {
	private String packName;
	private boolean userApp;
	public String getPackName() {
		return packName;
	}

	public void setPackName(String packName) {
		this.packName = packName;
	}

	public boolean isUserApp() {
		return userApp;
	}

	public void setUserApp(boolean userApp) {
		this.userApp = userApp;
	}
}</span>

AppTools.java

<span style="font-size:18px;">package com.example.packages;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class AppTools {
	public static List<AppInfo> getAppInfos(Context context){
		PackageManager pm = context.getPackageManager();
		List<AppInfo> appInfos = new ArrayList<AppInfo>();
		List<PackageInfo> packInfos = pm.getInstalledPackages(0);
		for(PackageInfo packInfo : packInfos){
			AppInfo appInfo = new AppInfo();
			String packName = packInfo.packageName;
			appInfo.setPackName(packName);
			int flags = packInfo.applicationInfo.flags;//标识 
			if((ApplicationInfo.FLAG_SYSTEM & flags) ==0){
				//用户程序
				appInfo.setUserApp(true);
			}else{
				//系统程序
				appInfo.setUserApp(false);
			}
			appInfos.add(appInfo);
		}
		return appInfos;
	}
}</span>


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。