2015-12-3-获取Android已安装的app信息

获取包含activity应用的信息

PackageManager pm = getPackageManager(); // 获得PackageManager对象
Intent mainIntent = new Intent(Intent. ACTION_MAIN, null );
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfos = pm
            .queryIntentActivities(mainIntent, 0);
appList.clear();
for (ResolveInfo reInfo : resolveInfos) {
       // 可能一个包有多个图标
      LogExt. LogD(this, Thread. currentThread().getStackTrace(),
                   "reInfo.activityInfo.name=" + reInfo.activityInfo.name );
      String activityName = reInfo. activityInfo.name ; // 获得该应用程序的启动Activity的name
      String appLabel = (String) reInfo.loadLabel(pm); // 获得应用程序的Label
      Drawable icon = reInfo.loadIcon(pm); // 获得应用程序图标
       // 创建一个AppInfo对象,并赋值
      AppInfo tmpInfo = new AppInfo();
      tmpInfo. appName = appLabel;
      tmpInfo. packageName = reInfo.activityInfo .packageName ;
      tmpInfo. mainActivityName = activityName;
      tmpInfo. appIcon = icon;
       appList.add(tmpInfo);
}

获取所有的App信息

PackageManager pm = getPackageManager();
List<PackageInfo> packages = pm
//                      .getInstalledPackages(0);
            .getInstalledPackages(PackageManager. MATCH_DEFAULT_ONLY);
LogExt.LogD (this , Thread.currentThread ().getStackTrace(),
             "packages.size() = " + packages.size());
appList.clear();
for (int i = 0; i < packages.size(); i++) {
      PackageInfo packageInfo = packages.get(i);
      AppInfo tmpInfo = new AppInfo();
      tmpInfo. appName = packageInfo.applicationInfo .loadLabel(
                  getPackageManager()).toString();
      tmpInfo. packageName = packageInfo.packageName ;
      tmpInfo. versionName = packageInfo.versionName ;
      tmpInfo. versionCode = packageInfo.versionCode ;
      tmpInfo. appIcon = packageInfo.applicationInfo
                  .loadIcon(getPackageManager());
       appList.add(tmpInfo);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值