获取Android系统应用信息
<?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系统应用信息的更多相关文章
- 获取Java系统相关信息
package com.test; import java.util.Properties; import java.util.Map.Entry; import org.junit.Test; pu ...
- getprop 获取android系统属性
Android属性系统 property_get/property_set (很透彻)http://www.blogjava.net/MEYE/articles/359773.html getpro ...
- 获取 Android APP 版本信息工具类(转载)
获取 Android APP 版本信息工具类 获取手机APP版本信息工具类 1.获取版本名称 2.获取版本号 3.获取App的名称 package com.mingyue.nanshuibeidiao ...
- 如何获取Android系统中申请对象的信息
最近一直在做有关内存方面的优化工作,在做优化的过程,除了关注内存的申请量以及GC的情况之外,我们经常需要想方法找出是那些对象占用了大量内存,以及他们是如何导致GC的,这意味着我们需要获取对象申请的信息 ...
- adb获取Android系统属性(adb shell getprop ***)数据来源
在Android系统中,它的根文件系统下有几个用于启动系统时需要的配置文件: /init.rc /default.prop /system/build.prop 通常我们可以通过命令getprop获取 ...
- iOS获取iPhone系统等信息和服务器返回空的异常处理
前言: 在项目中经常会遇到需要获取系统的信息来处理一些特殊的需求和服务端返回为空的处理,写在这里只是笔记一下. 获取设备的信息 NSLog(@"globallyUniqueString=%@ ...
- Android初级教程获取手机系统联系人信息
在手机内部,对联系人信息存在对应的数据库.我们创建的而联系人信息都存在这张表中.如下是对数据库的截图,我已经对表和应该注意的地方做了红笔标注: 好了,现在可以根据数据库里面的数据来写代码了. 代码如下 ...
- 获取Android崩溃crash信息并写入日志发送邮件
一.实现Thread.UncaughtExceptionHandlerUnChecked异常发生时,由于没有相应的try…catch处理该异常对象,所以Java运行环境将会终止,程序将退出,也就是我们 ...
- 获取android手机联系人信息
package com.yarin.android.Examples_04_04; import android.app.Activity; import android.database.Curso ...
随机推荐
- 洛谷P3759 - [TJOI2017]不勤劳的图书管理员
Portal Description 给出一个\(1..n(n\leq5\times10^4)\)的排列\(\{a_n\}\)和数列\(\{w_n\}(w_i\leq10^5)\),进行\(m(m\l ...
- php那些坑
1.创建数组不是new array(),是$aaa=array(),没有new,数组可以传入键值$aaa=array("key"=>"value"); 2 ...
- Linux(15):shell 编程
shell基础 什么是 shell ? Shell是一个命令解释器,它的作用是解释执行用户输入的命令及程序等,用户输入一条命令, Shell 就解释执行一条. 这种从键盘一输入命令,就可以立即得到回应 ...
- localStorage增删改查
/** * 设置 本地缓存 */ export function setStorage(key, obj) { if (typeof obj === 'string') { localStorage. ...
- HDU 4770 Lights Against Dudely 暴力枚举+dfs
又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...
- linux下将目录授权给其他用户的步骤
1.更改目录所有者命令:chown -R 用户名称 目录名称2.更改目录权限命令:chmod -R 755 目录名称
- 通过Nginx 的反向代理来加强kibana的访问安全
https://blog.csdn.net/choelea/article/details/57406086
- vue之组件理解(一)
组件是可复用的 Vue 实例,所以它们与 new Vue 接收相同的选项,例如 data.computed.watch.methods 以及生命周期钩子等.仅有的例外是像 el 这样根实例特有的选项. ...
- Access restriction: The method 'CharacterEncoder.encode(byte[])' is not API...
问题描述:Access restriction: The method 'CharacterEncoder.encode(byte[])' is not API... 解决方法:这种错误是eclips ...
- 【chrome错误】Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-reso
使用ajax请求本地文件,chrome会报跨域错误. XMLHttpRequest cannot loadfile:///C:/Users/Li/Desktop/images/alist.json.C ...