Android如何獲取開機啟動項列表

weixin_34377065發表於2014-12-08
 static final String BOOT_START_PERMISSION = "android.permission.RECEIVE_BOOT_COMPLETED";
 

  public List<Map<String, Object>> fetch_installed_apps(){
         List<ApplicationInfo> packages = getPackageManager().getInstalledApplications();
         list = new ArrayList<Map<String, Object>>(packages.size());
         Iterator<ApplicationInfo> appInfoIterator = packages.iterator();
      
 
         while (appInfoIterator.hasNext()) {
             ApplicationInfo app = (ApplicationInfo) appInfoIterator.next();
            //查詢安裝的package是否有開機啟動許可權
            if(PackageManager.PERMISSION_GRANTED==
                          getPackageManager().checkPermission(BOOT_START_PERMISSION, app.packageName))
             {
                   String label = getPackageManager().getApplicationLabel(app).toString(); 
                   Drawable appIcon = getPackageManager().getApplicationIcon(app);
                   Map<String, Object> map = new HashMap<String, Object>();
                   map.put("name", label);
                   map.put("desc", app.packageName);
                   map.put("img",appIcon);
                   list.add(map);             
             }
          }
         return list;
  }

 

相關文章