码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-12-22 18:04:09      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

直接上代码:

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>


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

标签:

原文地址:http://blog.csdn.net/coderinchina/article/details/42082005

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!