Android 获得所有应用程序包

本文转载自:http://blog.sina.com.cn/s/blog_3e333c4a01015v3e.html

 1 推荐方法
 2 1、全部程序包
 3     private void queryFilterAppInfo() {  
 4         PackageManager pm = this.getPackageManager();  
 5         // 查询所有已经安装的应用程序  
 6         List<ApplicationInfo> listAppcations = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的
 7             for (ApplicationInfo app : listAppcations) {  
 8             AppInfo appInfo = new AppInfo();  
 9             appInfo.setAppLabel((String) app.loadLabel(pm));  
10             appInfo.setAppIcon(app.loadIcon(pm));  
11             appInfo.setPkgName(app.packageName);
12             mlistAppInfo.add(appInfo);   
13         }       
14     }
15    
16 2、 获得所有系统的
17     public void querySysAppInfo() {  
18         PackageManager pm = this.getPackageManager();
19         Intent intent = new Intent(Intent.ACTION_MAIN, null);  
20         intent.addCategory(Intent.CATEGORY_LAUNCHER);  
21         // 通过查询,获得所有ResolveInfo对象.  
22         List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);  
23          
24         for (ResolveInfo reInfo : resolveInfos) {  
25         String activityName = reInfo.activityInfo.name; // 获得该应用程序的启动Activity的name  
26         String pkgName = reInfo.activityInfo.packageName; // 获得应用程序的包名  
27         String appLabel = (String) reInfo.loadLabel(pm); // 获得应用程序的Label  
28         Drawable icon = reInfo.loadIcon(pm); // 获得应用程序图标  
29         System.out.println(appLabel + " activityName---" + activityName + " pkgName---" + pkgName);  
30         }    
31     } 
32 
33 
34 3、 最简单的方法   
35     public  boolean appIsInstalled(String packageName){
36         try {
37             PackageManager pm = this.getPackageManager();
38             pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
39             System.out.println("已安装"+packageName);
40         } catch (NameNotFoundException e) {
41             System.out.println("没有安装"+packageName);
42             return false;
43         }
44         return true;
45     }
46 
47 
48 4、获得所有包信息   
49     public void getInstallPackage() {
50         PackageManager packageManager = this.getPackageManager();
51         List<PackageInfo> packageInfoList=packageManager.getInstalledPackages(0);
52         mlistAppInfo.clear();  
53         for (int i=0;i<packageInfoList.size();i++) { 
54             PackageInfo pi = packageInfoList.get(i);
55             System.out.println((i+1)+":"+pi.toString());
56         }  
57     }
58 5、直接启动方法
59     public  void srartApp(String packageName){
60         Intent intent = this.getPackageManager().getLaunchIntentForPackage(packageName);
61         if(intent!=null)
62         startActivity(intent); //已安装包 直接启动
63     }

 

Android 获得所有应用程序包,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。