<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="应用程序列表"
        android:textSize="20dp"
        android:padding="5dp"
        android:background="@color/colorAccent"
        />

    <ListView
        android:id="@+id/list_ctn_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/app_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"/>

        <TextView
            android:id="@+id/app_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:layout_toRightOf="@id/app_logo"
            android:layout_centerVertical="true"
            android:textSize="20dp"
            />
    </RelativeLayout>
public class AppInfo {
    private Drawable app_logo;
    private String name;
    private String packName;

    public AppInfo() {
    }

    public AppInfo(Drawable app_logo, String name, String packName) {
        this.app_logo = app_logo;
        this.name = name;
        this.packName = packName;
    }

    public Drawable getApp_logo() {
        return app_logo;
    }

    public void setApp_logo(Drawable app_logo) {
        this.app_logo = app_logo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPackName() {
        return packName;
    }

    public void setPackName(String packName) {
        this.packName = packName;
    }
}
public class MainActivity extends AppCompatActivity {
    private ListView listView ;
    private List<AppInfo> data;
    private AppAdapter appAdapter;

    class AppAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = View.inflate(MainActivity.this, R.layout.list_ctn, null);
            }
            AppInfo appInfo = data.get(position);
            ImageView imageView = (ImageView) convertView.findViewById(R.id.app_logo);
            TextView name = (TextView) convertView.findViewById(R.id.app_name);
            imageView.setImageDrawable(appInfo.getApp_logo());
            name.setText(appInfo.getName());
            return convertView;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = (ListView) findViewById(R.id.list_ctn_main);
        data = getAllAppInfos();
        AppAdapter appAdapter = new AppAdapter();
        listView.setAdapter(appAdapter);
    }

    private List<AppInfo> getAllAppInfos() {
        List<AppInfo> list = new ArrayList<AppInfo>();
        PackageManager packageManager = getPackageManager();
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, 0);
        for (ResolveInfo ri : resolveInfos) {
            String packageName = ri.activityInfo.packageName;
            Drawable icon = ri.loadIcon(packageManager);
            String appName = ri.loadLabel(packageManager).toString();
            AppInfo appInfo = new AppInfo(icon, appName, packageName);
            list.add(appInfo);
        }
        return list;
    }
}

单击事件

长按删除更新列表

setAdapter和notify**都可以实现重新显示,前者会跳到list顶部,是因为重新渲染的ui,后者会使用所有缓存的item对象,前者不会

获取Android系统应用信息的更多相关文章

  1. 获取Java系统相关信息

    package com.test; import java.util.Properties; import java.util.Map.Entry; import org.junit.Test; pu ...

  2. getprop 获取android系统属性

    Android属性系统 property_get/property_set  (很透彻)http://www.blogjava.net/MEYE/articles/359773.html getpro ...

  3. 获取 Android APP 版本信息工具类(转载)

    获取 Android APP 版本信息工具类 获取手机APP版本信息工具类 1.获取版本名称 2.获取版本号 3.获取App的名称 package com.mingyue.nanshuibeidiao ...

  4. 如何获取Android系统中申请对象的信息

    最近一直在做有关内存方面的优化工作,在做优化的过程,除了关注内存的申请量以及GC的情况之外,我们经常需要想方法找出是那些对象占用了大量内存,以及他们是如何导致GC的,这意味着我们需要获取对象申请的信息 ...

  5. adb获取Android系统属性(adb shell getprop ***)数据来源

    在Android系统中,它的根文件系统下有几个用于启动系统时需要的配置文件: /init.rc /default.prop /system/build.prop 通常我们可以通过命令getprop获取 ...

  6. iOS获取iPhone系统等信息和服务器返回空的异常处理

    前言: 在项目中经常会遇到需要获取系统的信息来处理一些特殊的需求和服务端返回为空的处理,写在这里只是笔记一下. 获取设备的信息 NSLog(@"globallyUniqueString=%@ ...

  7. Android初级教程获取手机系统联系人信息

    在手机内部,对联系人信息存在对应的数据库.我们创建的而联系人信息都存在这张表中.如下是对数据库的截图,我已经对表和应该注意的地方做了红笔标注: 好了,现在可以根据数据库里面的数据来写代码了. 代码如下 ...

  8. 获取Android崩溃crash信息并写入日志发送邮件

    一.实现Thread.UncaughtExceptionHandlerUnChecked异常发生时,由于没有相应的try…catch处理该异常对象,所以Java运行环境将会终止,程序将退出,也就是我们 ...

  9. 获取android手机联系人信息

    package com.yarin.android.Examples_04_04; import android.app.Activity; import android.database.Curso ...

随机推荐

  1. BZOJ 1260: [CQOI2007]涂色paint【区间DP】

    Description 假设你有一条长度为5的木版,初始时没有涂过任何颜色.你希望把它的5个单位长度分别涂上红.绿.蓝.绿.红色,用一个长度为5的字符串表示这个目标:RGBGR. 每次你可以把一段连续 ...

  2. java面试题之sleep()和wait()方法的区别

    sleep方法: 属于Thread类中的方法:会导致程序暂停执行指定的时间,让出cpu该其他线程,但是他的监控状态依然保持着,当指定时间到了之后,又会自动恢复运行状态:在调用sleep方法的过程中,线 ...

  3. POJ1635 树的最小表示法(判断同构)

    Some major cities have subway systems in the form of a tree, i.e. between any pair of stations, ther ...

  4. linux 安装软件出现/tmp 磁盘不足时 解决方案

    1.解决办法 mkdir  文件夹——你可以使用的文件夹 比如说 mkdir /mnt/tmp 然后只要export TMPDIR=/mnt/tmp 这样就不会出现 tmp文件夹不够用的情况

  5. MongoDB GridFS(命令行+php操作)

    一.GridFS是什么 & 为什么需要它 我们知道目前MongoDB的BSON文件最大只能是16M,也就是说单个文档最多只能存储16M的数据,那么如果需要MongoDB存储超过16M的大文件该 ...

  6. WEB学习-HTML的骨架

    HTML的标准骨架 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

  7. profile, bashrc, source, setup.*sh

    一. source: 命令是使该文件立刻执行,这样刚才做的修改就可以立即生效了,否则要重新启动系统修改才能生效.(执行其后命令使之立即生效,不用重启) 二.bashrc: 1.linux系统:/etc ...

  8. python3.x之print()

    1.print内容 #!/usr/bin/python print('hello world')    //print("hello world") 2.print变量 #!/us ...

  9. 某考试 T1 sigfib

    设 g(x) = f(x) * x ,多项式 A = Σ g(i) * x^i , 多项式  B = Σ f(i) * x^i. 首先,g(x) = g(x-1) + g(x-2) + f(x-1) ...

  10. java list实现树形结构

    1.javabean import java.util.List; public class TreeNode { private String id; private String parentId ...