读取手机上所有应用程序并显示(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"
随机推荐
- blade and soul Personal Combos
Personal Combos Since Blade and Soul is mainly based on skills, the game is more interesting after y ...
- cron表达式使用详解
Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth Month ...
- jquery mobile 的优缺点
jQuery Mobile 优点 跨浏览器兼容性最好,几乎兼容所有的平台和浏览器: 入门简单,语法简洁,编码灵活,一些简单的应用直接用HTML既可实现,无需Javascript: 开源插件与第三方扩展 ...
- js变量及其作用域
Javascript和Java.C这些语言不同,它是一种无类型.弱检测的语言.它对变量的定义并不需要声明变量类型,我们只要通过赋值的形式,可以将各种类型的数据赋值给同一个变量 一.js变量的类型及 ...
- 【编辑器】【Sublime Text】使用笔记
1.安装 官网下载即可 2.插件 sublime-text - Sublime Text 怎么高亮 Markdown 的文件语法 设置Sublime为VIM模式 如何在sublime 里面设置 ver ...
- everthing 添加右键菜单
Tool --> Options --> General -->勾上 Show folder context menus
- [开发笔记]-未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService...匹配的导出【转载自:酷小孩】
原文地址:http://www.cnblogs.com/babycool/p/3199158.html 今天打算用VisualStudio2012做一个js效果页面测试的时候,打开VS2012新建项目 ...
- 使用CSS3线性渐变实现图片闪光划过效果
<p class="overimg"> <a><img src="http://www.nowamagic.net/librarys/ima ...
- MD5使用
MD5加密算法,即"Message-Digest Algorithm 5(信息-摘要算法)",它由MD2.MD3.MD4发展而来的一种单向函数算法(也就是HASH算法),它是国际著 ...
- html图片预览
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...