获取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 ...
随机推荐
- 关于java读取文件IO流学习总结(一)
IO流的分类: 1.根据流的数据对象来分: 高端流:所有的内存中的流都是高端流,比如:InputStreamReader 低端流:所有的外界设备中的流都是低端流,比如InputStream,Outpu ...
- 【2018.9.26】K-D Tree详解
网上对K-D-Tree的讲解不尽清晰,我学了很久都不会写,这里新开一文做一些讲解. 1.K-D-Tree是什么? K-DTree 即 K-Dimensional-Tree,常用来作空间划分及近邻搜索, ...
- angular中ng-repeat去重
[html] view plain copy print?在CODE上查看代码片派生到我的代码片 <div ng-app="myApp" ng-controller=&quo ...
- Aragorn's Story(hdu3966)
题意:给一棵树,并给定各个点权的值,然后有3种操作: I C1 C2 K: 把C1与C2的路径上的所有点权值加上K D C1 C2 K:把C1与C2的路径上的所有点权值减去K Q C:查询节点编号为C ...
- 假几何真逆序数 NB HDU3465
题意: 有n条直线,问他们两两在横坐标开区间(L,R)之间相交的个数 n=50000,暴力肯定就不用想了,如果在纸上画一画可以发现如果两条直线在(L,R)内相交,那么他们与x= L和x=R的交点序数是 ...
- 【HDOJ5950】Recursive sequence(矩阵乘法,快速幂)
题意:f[1]=a,f[2]=b,f[i]=2f[i-2]+f[i-1]+i^4(i>=3),多组询问求f[n]对2147493647取模 N,a,b < 2^31 思路:重点在于i^4的 ...
- 如何让Gridview在没有数据的时候显示表头[没有使用SqlDataSource控件时]
原文发布时间为:2008-08-03 -- 来源于本人的百度文章 [由搬家工具导入] 要看全文请点击http://blog.csdn.net/windok2004/archive/2007/10/28 ...
- android Activity生命周期的例子
package com.example.yanlei.yl2; import android.app.AlertDialog; import android.content.DialogInterfa ...
- Go -- 性能优化
今日头条使用 Go 语言构建了大规模的微服务架构,本文结合 Go 语言特性着重讲解了并发,超时控制,性能等在构建微服务中的实践. 今日头条当前后端服务超过80%的流量是跑在 Go 构建的服务上.微服务 ...
- ActiveMQ消息的延时和定时投递
ActiveMQ对消息延时和定时投递做了很好的支持,其内部启动Scheduled来对该功能支持,也提供了一个封装的消息类型:org.apache.activemq.ScheduledMessage,只 ...