读取手机上所有应用程序并显示(APP)
pd = ProgressDialog.show(getActivity(), "请稍候..", "正在收集软件信息...", true,false);
Thread thread = new Thread(this);
thread.start();
@Override
public void run() { if(mlistAppInfo==null){
mlistAppInfo = new ArrayList<AppInfo>();
queryAppInfo();
} handler.sendEmptyMessage(0); }
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
if(mlistAppInfo!=null&&mlistAppInfo.size()==1)
{
Intent intent = mlistAppInfo.get(0).getIntent();
startActivity(intent);
}
else if(mlistAppInfo!=null&&mlistAppInfo.size()>1){
View appView=LayoutInflater.from(getActivity()).inflate(R.layout.yue_list_new, null);
listview = (ListView) appView.findViewById(R.id.listview); BrowseApplicationInfoAdapter browseAppAdapter = new BrowseApplicationInfoAdapter(
getActivity(), mlistAppInfo);
listview.setAdapter(browseAppAdapter);
listview.setOnItemClickListener(LvxingbaoFragment.this); new AlertDialog.Builder(getActivity()).setView(appView).show();
}
pd.dismiss();
}
}; public void queryAppInfo() {
PackageManager pm = getActivity().getPackageManager(); // 获得PackageManager对象
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// 通过查询,获得所有ResolveInfo对象.
List<ResolveInfo> resolveInfos = pm
.queryIntentActivities(mainIntent, 0);
// 调用系统排序 , 根据name排序
// 该排序很重要,否则只能显示系统应用,而不能列出第三方应用程序
Collections.sort(resolveInfos,new ResolveInfo.DisplayNameComparator(pm));
if (mlistAppInfo != null) {
mlistAppInfo.clear();
for (ResolveInfo reInfo : resolveInfos) { String appLabel = (String) reInfo.loadLabel(pm); String activityName = reInfo.activityInfo.name;
String pkgName = reInfo.activityInfo.packageName; // 获得应用程序的包名
// String appLabel = (String) reInfo.loadLabel(pm); // 获得应用程序的Label
Drawable icon = reInfo.loadIcon(pm); // 获得应用程序图标
// 为应用程序的启动Activity 准备Intent
Intent launchIntent = new Intent();
launchIntent.setComponent(new ComponentName(pkgName,
activityName)); // 创建一个AppInfo对象,并赋值
AppInfo appInfo = new AppInfo();
appInfo.setAppLabel(appLabel);
appInfo.setPkgName(pkgName);
appInfo.setAppIcon(icon);
appInfo.setIntent(launchIntent); mlistAppInfo.add(appInfo); // 添加至列表中 // String activityName = reInfo.activityInfo.name; // 获得该应用程序的启动Activity的name // System.out.println(appLabel + " activityName---" + activityName
// + " pkgName---" + pkgName);
}
}
} class BrowseApplicationInfoAdapter extends BaseAdapter { private List<AppInfo> mlistAppInfo = null; LayoutInflater infater = null; public BrowseApplicationInfoAdapter(Context context, List<AppInfo> apps) {
infater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mlistAppInfo = apps ;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
System.out.println("size" + mlistAppInfo.size());
return mlistAppInfo.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mlistAppInfo.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertview, ViewGroup arg2) {
System.out.println("getView at " + position);
View view = null;
ViewHolder holder = null;
if (convertview == null || convertview.getTag() == null) {
view = infater.inflate(R.layout.item_add_score, null);
holder = new ViewHolder(view);
view.setTag(holder);
}
else{
view = convertview ;
holder = (ViewHolder) convertview.getTag() ;
}
AppInfo appInfo = (AppInfo) getItem(position);
holder.appIcon.setImageDrawable(appInfo.getAppIcon());
holder.tvAppLabel.setText(appInfo.getAppLabel());
//holder.tvPkgName.setText(appInfo.getPkgName());
return view;
} }
class ViewHolder {
ImageView appIcon;
TextView tvAppLabel;
//TextView tvPkgName; public ViewHolder(View view) {
this.appIcon = (ImageView) view.findViewById(R.id.add_score_app_img);
this.tvAppLabel = (TextView) view.findViewById(R.id.add_score_app_name);
// this.tvPkgName = (TextView) view.findViewById(R.id.tvPkgName);
}
} class AppInfo { private String appLabel; //应用程序标签
private Drawable appIcon ; //应用程序图像
private Intent intent ; //启动应用程序的Intent ,一般是Action为Main和Category为Lancher的Activity
private String pkgName ; //应用程序所对应的包名 public AppInfo(){} public String getAppLabel() {
return appLabel;
}
public void setAppLabel(String appName) {
this.appLabel = appName;
}
public Drawable getAppIcon() {
return appIcon;
}
public void setAppIcon(Drawable appIcon) {
this.appIcon = appIcon;
}
public Intent getIntent() {
return intent;
}
public void setIntent(Intent intent) {
this.intent = intent;
}
public String getPkgName(){
return pkgName ;
}
public void setPkgName(String pkgName){
this.pkgName=pkgName ;
}
}
读取手机上所有应用程序并显示(APP)的更多相关文章
- 安卓手机上运行 PC-E500 程序
目录 第1章安卓手机上运行 PC-E500 程序 1 1 PockEmul 1 2 下载 1 3 打包BASIC程序 2 4 配置PC-E500模拟器 5 5 载入e50 ...
- 在Android手机上学习socket程序
我们都知道Android手机是基于Linux系统的,在没有Linux环境,但是想学习socket编程的同学可以在Android手机中试试,利用ndk编译可执行文件在Android手机中运行.不同于动态 ...
- WebStorm技巧-在安卓手机上运行Ionic程序
打开菜单项 Run -> Run- 选择 Edit Configurations- 添加一个 PhoneGap/Cordova 配置项,命名如: Ionic Android, 并输入相关 ...
- 在 Android 手机上运行 Python 程序
- Mac电脑如何读取Android手机上的文件
问题 一般Android手机用usb数据线连接到windows操作系统的电脑上后,会自动将手机存储卡以移动存储的方式显示在电脑里. 但是如果操作系统是Mac的,就没有这个存储设备.问题来了,Mac电脑 ...
- 我手机上常用的app和常访问的网站
====常用======Opera Mini browser 浏览器(版本26.0.2254.117241以上) 老版本7.7最最经典, 但该版本在新的安卓手机上总有部分区域显示空白. 现在的 Ope ...
- 【Android】读取sdcard卡上的全部图片而且显示,读取的过程有进度条显示
尽管以下的app还没有做到快图浏览.ES文件浏览器的水平,遇到大sdcard还是会存在读取过久.内存溢出等问题,可是基本思想是这种. 例如以下图.在sdcard卡上有4张图片, 打开app,则会吧sd ...
- 在iPhone手机上写了input type="date" 显示不出来的原因
在iPhone手机上写了input type="date" 显示不出来的原因 今天在手机页面上使用新的input类型,这样子写,在chrome浏览器上浏览,很好,显示出来.然后用i ...
- 当EditText编辑时 hint 在 6.0 手机上显示不出来
当EditText编辑时 hint 在 6.0 手机上显示不出来.... 就要增加一句话去重新设置颜色值 Android:textColorHint = "#707070"
随机推荐
- int unsigned实验
create table t1(a int unsigned,b int unsigned); insert into t1 select 1,2; select 1-2 from t1; Error ...
- 框架 Onboard-引导页样式制作库
设置背景图片或者背景movie,然后在它们之上生成数个ViewController,默认是顶部一张图片,下面是标题和详细介绍,最下面是按钮和pagegithub地址 https://github.c ...
- css3实现逐渐变大的圆填充div背景的效果
手机端现在的一些应用会运用上这样一个效果,就是duang的一下出现一个圆变大直到填充整个div,动感十足. 想到css3的scale属性,就自己来实现一下. <div id="bcd& ...
- iOS 开发之控件快速学习(一)
最近一个朋友想转iOS所以我开始写一些初级iOS学习博客!也希望第一些初学的朋友有所帮助,!好吧进入今天的正题,我们今天主要完成如下界面的显示! 好的一起打开Xcode一下几步我截图说明:
- DeviceIoControl 应用层如何和驱动层通信?
调用的方法之一的DeviceIoControl 驱动层提供设备名 例如filedisk 在驱动层 首先先是注册列表 用winObj查看 filedisk的驱动对象 但是 这八个对象时怎么生成的呢? 我 ...
- js生成[n,m]的随机数 以及实际运用
Math.ceil(); //向上取整. Math.floor(); //向下取整. Math.round(); //四舍五入. Math.random(); //0.0 ~ 1.0 之间的一 ...
- Python Day 01
What is variables? 一段命名的内存空间 变量即在程序运行过程中,它的值是允许改变的量 1.变量命名: 合法: 显式.通俗易懂. nums_of_jay_gf = 19 NumsOfJ ...
- JavaScript贷款计算器
今天花了两个小时模仿书上代码用JS制作了JavaScript贷款计算器,时间有些长,但相比以前,自己细心了不少,每天进步一点点,量的积累达到质的飞跃 <!doctype html>< ...
- DotNetBar for Windows Forms 12.9.0.0_冰河之刃重打包版及制作Visual Studio C#项目模板文件详解
关于 DotNetBar for Windows Forms 12.9.0.0_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版-------------- ...
- java基础之 重排序
重排序通常是编译器或运行时环境为了优化程序性能而采取的对指令进行重新排序执行的一种手段.重排序分为两类:编译期重排序和运行期重排序,分别对应编译时和运行时环境. 在并发程序中,程序员会特别关注不同进程 ...