java实现获取安卓设备里已安装的软件包
之前的文章向大家介绍了几个项目中常用的实用功能,那么在这篇文中,我将向大家介绍如何获取Android手机中已经安装的手机应用程序,好了,废话不多说,直接上代码
private String getInstalledAppListAsString(){ PackageManager pm = context.getPackageManager(); List<ApplicationInfo> apps = pm.getInstalledApplications(PackageManager.GET_GIDS); StringBuffer stringBuffer = new StringBuffer(); for (ApplicationInfo app : apps) { if(pm.getLaunchIntentForPackage(app.packageName) != null) { // apps with launcher intent if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) { // updated system apps } else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) { // system apps } else { // user installed apps stringBuffer.append(app.packageName).append(';'); } } } return stringBuffer.toString(); }
下面我们看看具体如何获取各个应用的相关信息呢
package cn.lyz.mobilesafe.domain; import android.graphics.drawable.Drawable; /** * 获取的应用基本信息实体类 * @author liuyazhuang * */ public class AppInfo { //图标 private Drawable app_icon; //应用名称 private String app_name; //应用版本号 private String app_version; //应用包名 private String packagename; //是否是用户app private boolean isUserApp; public AppInfo() { super(); // TODO Auto-generated constructor stub } public AppInfo(Drawable app_icon, String app_name, String app_version, String packagename) { super(); this.app_icon = app_icon; this.app_name = app_name; this.app_version = app_version; this.packagename = packagename; } public AppInfo(Drawable app_icon, String app_name, String app_version, String packagename, boolean isUserApp) { super(); this.app_icon = app_icon; this.app_name = app_name; this.app_version = app_version; this.packagename = packagename; this.isUserApp = isUserApp; } public Drawable getApp_icon() { return app_icon; } public void setApp_icon(Drawable app_icon) { this.app_icon = app_icon; } public String getApp_name() { return app_name; } public void setApp_name(String app_name) { this.app_name = app_name; } public String getApp_version() { return app_version; } public void setApp_version(String app_version) { this.app_version = app_version; } public String getPackagename() { return packagename; } public void setPackagename(String packagename) { this.packagename = packagename; } public boolean isUserApp() { return isUserApp; } public void setUserApp(boolean isUserApp) { this.isUserApp = isUserApp; } @Override public String toString() { return "AppInfo [app_icon=" + app_icon + ", app_name=" + app_name + ", app_version=" + app_version + ", packagename=" + packagename + ", isUserApp=" + isUserApp + "]"; } }
赞 (0)