java实现获取安卓设备里已安装的软件包
之前的文章向大家介绍了几个项目中常用的实用功能,那么在这篇文中,我将向大家介绍如何获取Android手机中已经安装的手机应用程序,好了,废话不多说,直接上代码
privateStringgetInstalledAppListAsString(){ PackageManagerpm=context.getPackageManager(); List<ApplicationInfo>apps=pm.getInstalledApplications(PackageManager.GET_GIDS); StringBufferstringBuffer=newStringBuffer(); for(ApplicationInfoapp:apps){ if(pm.getLaunchIntentForPackage(app.packageName)!=null){ //appswithlauncherintent if((app.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)==1){ //updatedsystemapps }elseif((app.flags&ApplicationInfo.FLAG_SYSTEM)==1){ //systemapps }else{ //userinstalledapps stringBuffer.append(app.packageName).append(';'); } } } returnstringBuffer.toString(); }
下面我们看看具体如何获取各个应用的相关信息呢
packagecn.lyz.mobilesafe.domain; importandroid.graphics.drawable.Drawable; /** *获取的应用基本信息实体类 *@authorliuyazhuang * */ publicclassAppInfo{ //图标 privateDrawableapp_icon; //应用名称 privateStringapp_name; //应用版本号 privateStringapp_version; //应用包名 privateStringpackagename; //是否是用户app privatebooleanisUserApp; publicAppInfo(){ super(); //TODOAuto-generatedconstructorstub } publicAppInfo(Drawableapp_icon,Stringapp_name,Stringapp_version, Stringpackagename){ super(); this.app_icon=app_icon; this.app_name=app_name; this.app_version=app_version; this.packagename=packagename; } publicAppInfo(Drawableapp_icon,Stringapp_name,Stringapp_version, Stringpackagename,booleanisUserApp){ super(); this.app_icon=app_icon; this.app_name=app_name; this.app_version=app_version; this.packagename=packagename; this.isUserApp=isUserApp; } publicDrawablegetApp_icon(){ returnapp_icon; } publicvoidsetApp_icon(Drawableapp_icon){ this.app_icon=app_icon; } publicStringgetApp_name(){ returnapp_name; } publicvoidsetApp_name(Stringapp_name){ this.app_name=app_name; } publicStringgetApp_version(){ returnapp_version; } publicvoidsetApp_version(Stringapp_version){ this.app_version=app_version; } publicStringgetPackagename(){ returnpackagename; } publicvoidsetPackagename(Stringpackagename){ this.packagename=packagename; } publicbooleanisUserApp(){ returnisUserApp; } publicvoidsetUserApp(booleanisUserApp){ this.isUserApp=isUserApp; } @Override publicStringtoString(){ return"AppInfo[app_icon="+app_icon+",app_name="+app_name +",app_version="+app_version+",packagename=" +packagename+",isUserApp="+isUserApp+"]"; } }