获取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 ...
随机推荐
- BZOJ2288 【POJ Challenge】生日礼物 【堆 + 链表】
题目 ftiasch 18岁生日的时候,lqp18_31给她看了一个神奇的序列 A1, A2, ..., AN. 她被允许选择不超过 M 个连续的部分作为自己的生日礼物. 自然地,ftiasch想要知 ...
- 算法复习——欧拉回路混合图(bzoj2095二分+网络流)
题目: Description YYD为了减肥,他来到了瘦海,这是一个巨大的海,海中有n个小岛,小岛之间有m座桥连接,两个小岛之间不会有两座桥,并且从一个小岛可以到另外任意一个小岛.现在YYD想骑单车 ...
- 刷题总结——烽火传递(单调队列+dp)
题目: 题目描述 烽火台又称烽燧,是重要的防御设施,一般建在险要处或交通要道上.一旦有敌情发生,白天燃烧柴草,通过浓烟表达信息:夜晚燃烧干柴,以火光传递军情.在某两座城市之间有 n 个烽火台,每个烽火 ...
- C#.net的常用函数列表
原文发布时间为:2008-08-03 -- 来源于本人的百度文章 [由搬家工具导入] 1、DateTime 数字型 System.DateTime currentTime=new System.Dat ...
- R语言入门视频笔记--10--数据挖掘
这里来挖掘超市购物车数据. 名词: 1.挖掘数据集:购物篮数据 2.挖掘目标:关联规则 3.关联规则:牛奶=>鸡蛋[支持度=2%,置信度=60%] 4.指出度:分析中的全部事务的2%同时购买了牛 ...
- 更改navigationBar 颜色
if (IS_IOS7()) { /* iOS7 时 Navigation 颜色 */ [[UINavigationBar appearance] setBarTintColor: HexCo ...
- Android借助Handler,实现ViewPager中页面的自动切换(转)
在很多电商网页及app上都有自动切换的商品的推广快,感觉体验挺不错的,正好今天学习使用ViewPager,因此也实现了一个功能类似的demo. 下面是其中的两个截图: 实现一个自动 ...
- I.Tower Defense
给你p个重塔,q个轻塔,把这些塔放在n*m的图中,这些塔会相互攻击同行同列的,轻塔不能受到攻击,重塔能承受一个塔的攻击, 问放的方法数. 先假定n < m. 可以先枚举放轻塔的个数为s,显然,方 ...
- mysql主从库
http://wangwei007.blog.51cto.com/68019/965575 一.mysql主从的原理 1.Replication 线程 Mysql的 Replication 是一个异步 ...
- jfinal使用idea启动 访问报404 action not found
公司一个项目,在eclipse里面启动正常,换到idea里面启动后,启动没有报错,但是访问的时候会提示404 action not found. 百度了很多种解决方法 都没有解决. 今天脑子一转,想到 ...