• 获取设备上全部系统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;
    	}
    
    }
    


     

  • 相关阅读:
    [CTSC2018] 暴力写挂
    [20220210联考] 传染
    [20220208联考] 差量
    [20220214联考] 树上的棋局
    [JSOI2004] 平衡点 / 吊打XXX
    [CodeChef] Maximum and Minimum
    [20220210联考] 一般图带权多重匹配
    [NOI2019] 弹跳
    不可视境界线
    08 | 白话容器基础(四):重新认识Docker容器
  • 原文地址:https://www.cnblogs.com/blfshiye/p/5267093.html
Copyright © 2020-2023  润新知