2014-03-28 72 views
-1

我想獲取安卓手機中安裝的所有應用程序的列表。通過以下代碼,我只能獲取用戶安裝的應用程序,但我也想獲得系統應用程序。獲取安卓手機中的所有應用程序

packageManager = getPackageManager(); 
     List<PackageInfo> packageList = packageManager.getInstalledPackages(packageManager.GET_PERMISSIONS);//PackageManager.GET_META_DATA 

    List<PackageInfo> packageList1 = new ArrayList<PackageInfo>(); 
    PackageManager pm = this.getPackageManager(); 
    /*To filter out System apps*/ 
    for(PackageInfo pi : packageList) { 
     boolean b = isSystemPackage(pi); 
     if(!b) { 
      packageList1.add(pi); 
     } 
    } 
    apkList = (ListView) findViewById(R.id.AppList); 
    apkList.setAdapter(new ApkAdapter(this, packageList1, packageManager)); 

    apkList.setOnItemClickListener(this); 
} 

private boolean isSystemPackage(PackageInfo pkgInfo) { 
     return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true 
       : false; 
    } 

回答

0

試試這個:

final PackageManager pm = getActivity().getPackageManager(); 
Intent intent = new Intent(Intent.ACTION_MAIN, null); 
intent.addCategory(Intent.CATEGORY_LAUNCHER); 
List<ResolveInfo> apps = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA); 

希望它會幫助你..!

+0

它不給我所有的應用程序 –

+0

輸出是什麼? – Lokesh

+0

它只給用戶安裝的應用程序 –

相關問題