java实现获取安卓设备里已安装的软件包
更新时间:2015年10月29日 11:25:29 投稿:hebedich
本文给大家介绍的是如何获取设备中已经安装的应用软件包的代码,其核心方法原理很简单,我们通过Android中提供的PackageManager类,来获取手机中安装的应用程序信息
之前的文章向大家介绍了几个项目中常用的实用功能,那么在这篇文中,我将向大家介绍如何获取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 + "]"; } }
您可能感兴趣的文章:
相关文章
IDEA报错Error running‘Application‘:Command line is too lo
这篇文章主要介绍了IDEA报错Error running ‘Application‘:Command line is too long的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2024-06-06BeanFactory和FactoryBean的区别示例详解
这篇文章主要为大家介绍了BeanFactory和FactoryBean的区别示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-10-10
最新评论