读取手机上所有应用程序并显示(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"
随机推荐
- LeetCode 5 Longest Palindromic Substring manacher算法,最长回文子序列,string.substr(start,len) 难度:2
https://leetcode.com/problems/longest-palindromic-substring/ manacher算法相关:http://blog.csdn.net/ywhor ...
- python 获取脚本所在目录
平时写python经常会想获得脚本所在的目录,例如有个文件跟脚本文件放在一个相对的目录位置,那就可以通过脚本文件的目录找到对应的文件,即使以后脚本文件移到其他地方,脚本也基本不需要改动(相对于写死目录 ...
- sql高级语句大全
经典SQL语句大全 一.基础 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql s ...
- 移除project,testsuite,testcase级别所有的custom properties
// Remove all custom properties on Project level. If removed, custom properties cannnot be injected ...
- CnBlog客户端Windows Live Write安装方法
官方帮助http://space.cnblogs.com/forum/topic/8550 注:如果自动配置没有成功,需要手动配置: a) 在"Type of weblog that yo ...
- C++初始化列表
C++初始化列表 定义一个类对象时,常常使用初始化列表实例化一个对象,在进入构造函数函数体之前对成员变量完成初始化操作.普通成员变量既可以在初始化中初始化,也可以在函数体重赋值:const成员变量只能 ...
- unslider.js 实现移动web轮播
unslider.js可以实现轮播,但是在移动端还需要另两个插件. jquery.event.move和jQuery.event.swipe : 下面就是简单的实例: <!doctype htm ...
- shape的简单用法
shap节点-----------------------------------定义shape的值,必须是下面的之一:"rectangle" 矩阵,这也是默认的shape&quo ...
- http 请求详解大全
HTTP 100 Continue继续 101 Switching Protocols切换协议 200 OK正常 201 Created已创建 202 Accepted已接受 203 Non-Auth ...
- leetcode Online Judge 150题 解答分析之一 Reverse Words in a String
问题 Given an input string, reverse the string word by word. For example, Given s = "the sky is b ...