1.java代码
package eoe.appshow;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class AppShowActivity extends Activity {
ListView lv;
MyAdapter adapter;
ArrayList<HashMap<String, Object>> items = new ArrayList<HashMap<String, Object>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv = (ListView)findViewById(R.id.lv);
//得到PackageManager对象
PackageManager pm = getPackageManager();
//得到系统安装的所有程序包的PackageInfo对象
//List<ApplicationInfo> packs = pm.getInstalledApplications(0);
List<PackageInfo> packs = pm.getInstalledPackages(0);
for(PackageInfo pi:packs)
{
HashMap<String, Object> map = new HashMap<String, Object>();
//显示用户安装的应用程序,而不显示系统程序
// if((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)==0&&
// (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)==0)
// {
// //这将会显示所有安装的应用程序,包括系统应用程序
// map.put("icon", pi.applicationInfo.loadIcon(pm));//图标
// map.put("appName", pi.applicationInfo.loadLabel(pm));//应用程序名称
// map.put("packageName", pi.applicationInfo.packageName);//应用程序包名
// //循环读取并存到HashMap中,再增加到ArrayList上,一个HashMap就是一项
// items.add(map);
// }
//这将会显示所有安装的应用程序,包括系统应用程序
map.put("icon", pi.applicationInfo.loadIcon(pm));//图标
map.put("appName", pi.applicationInfo.loadLabel(pm));//应用程序名称
map.put("packageName", pi.applicationInfo.packageName);//应用程序包名
//循环读取并存到HashMap中,再增加到ArrayList上,一个HashMap就是一项
items.add(map);
}
/**
* 参数:Context
* ArrayList(item的集合)
* item的layout
* 包含ArrayList中的HashMap的key的数组
* key所对应的值的相应的控件id
*/
adapter = new MyAdapter(this, items, R.layout.piitem,
new String[]{"icon", "appName", "packageName"},
new int[]{R.id.icon, R.id.appName, R.id.packageName});
lv.setAdapter(adapter);
}
}
class MyAdapter extends SimpleAdapter
{
private int[] appTo;
private String[] appFrom;
private ViewBinder appViewBinder;
private List<? extends Map<String, ?>> appData;
private int appResource;
private LayoutInflater appInflater;
public MyAdapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
appData = data;
appResource = resource;
appFrom = from;
appTo = to;
appInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(int position, View convertView, ViewGroup parent){
return createViewFromResource(position, convertView, parent, appResource);
}
private View createViewFromResource(int position, View convertView, ViewGroup parent, int resource){
View v;
if(convertView == null)
{
v = appInflater.inflate(resource, parent,false);
final int[] to = appTo;
final int count = to.length;
final View[] holder = new View[count];
for(int i = 0; i < count; i++)
{
holder[i] = v.findViewById(to[i]);
}
v.setTag(holder);
}else
{
v = convertView;
}
bindView(position, v);
return v;
}
private void bindView(int position, View view)
{
final Map dataSet = appData.get(position);
if(dataSet == null)
{
return;
}
final ViewBinder binder = appViewBinder;
final View[] holder = (View[])view.getTag();
final String[] from = appFrom;
final int[] to = appTo;
final int count = to.length;
for(int i = 0; i < count; i++)
{
final View v = holder[i];
if(v != null)
{
final Object data = dataSet.get(from[i]);
String text = data == null ? "":data.toString();
if(text == null)
{
text = "";
}
boolean bound = false;
if(binder != null)
{
bound = binder.setViewValue(v, data, text);
}
if(!bound)
{
/**
* 自定义适配器,关在在这里,根据传递过来的控件以及值的数据类型,
* 执行相应的方法,可以根据自己需要自行添加if语句。另外,CheckBox等
* 集成自TextView的控件也会被识别成TextView,这就需要判断值的类型
*/
if(v instanceof TextView)
{
//如果是TextView控件,则调用SimpleAdapter自带的方法,设置文本
setViewText((TextView)v, text);
}else if(v instanceof ImageView){
//如果是ImageView控件,调用自己写的方法,设置图片
setViewImage((ImageView)v, (Drawable)data);
}else{
throw new IllegalStateException(v.getClass().getName() + " is not a " + "view that can be bounds by this SimpleAdapter");
}
}
}
}
}
public void setViewImage(ImageView v, Drawable value){
v.setImageDrawable(value);
}
}
2. main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/lv" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
3.piitem.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/icon"
android:layout_width="48dip"
android:layout_height="48dip" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/appName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/packageName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
分享到:
相关推荐
里面有2个源码包,分别用两种方式获得系统所安装的应用程序,并用listview和gridview两种布局方式分别显示出来。 通过遍历List,里面的每一个ResolveInfo就是一个应用的 信息,将应用显示出来。
Dialog嵌套GridView显示系统已安装的应用程序,并能打开对应应用程序。
一个安卓开发的小例子 显示系统安装的应用程序
然后在搜索框(search)中填写你需要的软件名称搜索即可,或者在软件分类和推荐软件列表中找到你要安装的软件点击下载安装即可,如果是免费软件会显示为“Free”,如果是收费软件的话会提示软件的费用为“$xx”。...
要求在一个Activity中显示两个列表(用户应用程序列表和系统应用的列表) 用一个ListView列表,显示Android系统中安装的应用程序信息 (包括本程序的图标,程序名...用另一个ListView显示系统应用程序列表不加卸载按钮
[VS2005]解决“由于应用程序的配置不正确,应用程序未能启动,重新安装应用程序可能会纠正这个问题” 今天在准备发布用VS2005写的那个程序时,拷贝到我同事机器上,双击突然出现了“由于应用程序的配置不正确,...
方便的android 系统安装应用程序和游戏软件
该效果实现了采用GridView显示系统所安装的应用,该功能有别于原来的Launcher,主要是把竖向滑动改为横向...功能核心实现是先获取系统安装的应用程序,然后再根据设置的每页应该的大小来生成各个页面的内容等。
通过读取注册表获取所以已安装程序信息,包括名称,发行商,安装时间,版本号等信
由vba编写的一个excel工具类,检查当前系统安装的软件,但是据说绿色版的查不出,主要查找系统的注册表uninstall目录下的display name有这个名字的软件会显示
联想工程师专用小工具 开机提示svchost.exe应用程序错误修复工具V2.30.1联想工程师专用小工具 开机提示svchost.exe应用程序错误修复工具V2.30.1联想工程师专用小工具 开机提示svchost.exe应用程序错误修复工具V...
可以使用诸如TCPView或FPort等第三方工具来查找正在使用80端口的其它应用程序; 3、操作系统补丁所导致的。打开“添加删除程序”,勾选“显示更新”,在列表中找KB939373、 kB942830、KB942831这三个补丁,如果有...
NULL 博文链接:https://lovezhou.iteye.com/blog/894078
对于每个Windows应用程序,将显示以下信息:应用程序名称、应用程序版本、注册表名称、注册表修改时间、安装文件夹、安装文件夹所有者、卸载命令等... InstalledAppView允许您从本地系统、网络上的远程计算机以及插入...
V3虚拟机应用程序,系统中的系统,实现多系统互相应用 不想干扰
待办事项列表应用程序仅使用 C++ 编程语言创建。该系统是一种用户友好的系统,可以轻松修改。该系统可以为您提供一种管理日常任务的有效方式。该系统是开放访问的,您无需输入任何用户登录信息即可访问系统。该系统...
WindowBlinds是一款专门的Windows系统美化应用程序,尤其是对全体Windows应用程序窗口的更改,安装和运行非常简单。Window Blinds安装后可以整合于Windows操作系统中。而且该软件是目前惟一获得微软许可的第三方系统...
这是一个简单易用的免费软件应用程序,它将告诉您有关PC的大多数信息。 无需安装,如果要对另一个Windows系统进行故障排除,甚至可以从USB闪存驱动器运行它。 1.只需双击WinAudit.exe,即可开始滚动。 它将在...
LED显示屏的下位机和上位机的指导开发。开发出的LED显示屏控制系统能够很好满足工程设计的需要,节省了控制系统开发的周期,使得控制更加方便、灵活,在实际应用中取得较好的效果。希望有帮助
今天,小智就推荐大家一款无需root、卸装系统应用神器——Debloater Debloater是一款Windows平台上的软件,可以通过adb命令,禁用安卓系统中几乎所有的App。实际上安卓系统一直带有禁用App的功能,但这个功能...