2012-11-16 58 views
0

可能重複:
How do I check if an app is a non-system app in Android?如何獲得已安裝的應用程序列表,但不包括系統應用程序?

在此代碼返回的一切,包括系統應用程序,如Android系統和時鐘的時刻。

public List<ApplicationInfo> getApps() { 
     final PackageManager pm = context.getPackageManager(); 
     List<ApplicationInfo> packages = pm 
       .getInstalledApplications(PackageManager.GET_META_DATA); 
     return packages; 
    } 

如何區分這些和用戶安裝的應用程序?

+2

http://stackoverflow.com/questions/8784505/how-do-i-check-if-an-app-is-a-non-system代碼-app-in-android – Nermeen

回答

9

嗨,你可以使用下面

for(ApplicationInfo app : apps) { 
     //checks for flags; if flagged, check if updated system app 
     if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) { 
      installedApps.add(app); 
     //it's a system app, not interested 
     } else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) { 
      //Discard this one 
     //in this case, it should be a user-installed app 
     } else { 
      installedApps.add(app); 
     } 
    } 
+0

這很完美!感謝那... – davidOhara

相關問題