首页 > 代码库 > 获取设备上所有系统app信息

获取设备上所有系统app信息

在获取android设备的所有程序信息一文中介绍了获取手机上所有app信息的方法,下面介绍过滤掉系统app的方法:

MainActivity:

package com.home.getsysapp;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import android.app.Activity;import android.content.pm.ApplicationInfo;import android.content.pm.PackageInfo;import android.os.Bundle;import android.widget.ListView;import android.widget.SimpleAdapter;public class MainActivity extends Activity {	@Override	protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		ListView listView = new ListView(this);		List<Map<String, String>> list = getSysApps();		SimpleAdapter adapter = new SimpleAdapter(this, list,				android.R.layout.simple_list_item_2, new String[] { "appname",						"pname" }, new int[] { android.R.id.text1,						android.R.id.text2, });		listView.setAdapter(adapter);		setContentView(listView);	}	/**	 * 获取系统apps	 * 	 * @return	 */	private List<Map<String, String>> getSysApps() {		List<Map<String, String>> list = new ArrayList<Map<String, String>>();		Map<String, String> map = null;		List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);		for (PackageInfo p : packs) {			ApplicationInfo appInfo = p.applicationInfo;			// 为0表示非系统的,为1表示系统的			if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0) {				map = new HashMap<String, String>();				String appName = appInfo.loadLabel(getPackageManager())						.toString();				String pname = appInfo.packageName;				map.put("appname", appName);				map.put("pname", pname);				list.add(map);			}		}		return list;	}}