在监听应用的安装和卸载后,我需要刷新应用列表,但是BroadcastReceiver返回的只是包名String packageName,我要怎么得到PackageManager对象来获得对应应用的应用名和图标呢?
if(intent.getAction().equals("android.intent.action.PACKAGE_ADDED")){
String packageName = intent.getDataString();
Toast.makeText(context, "安装了:"+packageName,Toast.LENGTH_LONG).show();
for(ResolveInfo info : MainActivity.packs){
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("icon", info.loadIcon(packageName));
map.put("name", info.loadLabel(packageName));
MainActivity.listItems.remove(map); //添加到列表
}
MainActivity.myAdapter.notifyDataSetChanged();
帮顶