读取手机上所有应用程序并显示(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"
随机推荐
- SQLSERVER2008R2数据库的整体导出及单个表的导出步骤
今天在同事导SQLSERVER数据库中的表的时候遇到一问题,不知道怎么单独的把一个表的建表语句导出来,,迅速百度一下,按照步骤还真导出来了,导出单个表的步骤看下面来啦....: 点中数据库名字---- ...
- ORACLE中的支持正则表达式的函数
ORACLE中的支持正则表达式的函数主要有下面四个:1,REGEXP_LIKE :与LIKE的功能相似2,REGEXP_INSTR :与INSTR的功能相似3,REGEXP_SUBSTR :与SUBS ...
- Yii2.0数据库操作增删改查详解
1.简单查询: one(): 根据查询结果返回查询的第一条记录. all(): 根据查询结果返回所有记录. count(): 返回记录的数量. sum(): 返回指定列的总数. average(): ...
- android两种基本联网方式与一种第三方开源项目的使用
安卓请求网络的三种方式 在请求网络的时候一般常用的提交方式是post或者get请求,post请求安全,传输大小无限制,但是代码量多些,get请求是浏览器有大小限制,用户提交的信息在浏览器的地址栏显示出 ...
- 基础篇-初步认识PE格式
1 PE(Portable Executable)格式,是Win32环境可移植可执行文件(如exe.dll.vxd.sys和vdm等)的标准文件格式.PE格式衍生于早期建立在VAX(R)VMS(R)上 ...
- 金山软件wps2012-2013通杀0day
#!/usr/bin/python # Exploit Title: Kingsoft Office Writer v2012 8.1.0.3385 .wps Buffer Overflow Expl ...
- Web安全
随着Web2.0.网络社交等一系列新型的互联网产品的诞生,基于Web环境的互联网应用越来越广泛,企业信息化的过程中,越来越多的应用都架设在Web平台上.Web业务的迅速发展吸引了黑客们的强烈关注,接踵 ...
- isMobile
var isMobile = { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: ...
- Copy page via powershell and not save as template 分类: Sharepoint 2015-07-16 16:39 4人阅读 评论(0) 收藏
By save as template informaton of the page get lost, e.g. permissions. To avoid this, use powershell ...
- math and date、ajax、画布
console.log(Math.PI);//圆周率 console.log(Math.sqrt(4));//平方根2 console.log(Math.abs(-2.3));//绝对值2.3 con ...