2012-10-25 20 views
0

我想知道是否可以檢查應用程序是否附帶Android,例如:圖庫,聯繫人,下載,電子郵件等。所有這些類型的應用程序都是我想從列表中排除的應用程序創建,但不想硬編碼的名稱。如何檢查應用程序是否隨操作系統一起提供?

這是我用搶的應用程序名稱代碼:

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
    final List pkgList = getApplicationContext().getPackageManager().queryIntentActivities(mainIntent, 0); 

pkgList包含ResolveInfo對象。

編輯:檢查應用程序的Android操作系統的一部分,是檢查是否ResolveInfo.activityInfo.applicationInfo.packageName包含「com.android」字符序列,但我仍然有興趣

的一種方式在一個更優雅的解決方案。

回答

1

參見this answer

基本上,這個:

PackageManager pm = getPackageManager(); 

//Gets the info for all installed applications 
List<ApplicationInfo> apps = pm.getInstalledApplications(0); 

for(ApplicationInfo app : apps) { 
    if((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) { 
     //It's a pre-installed app 
    } else if ((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) { 
     //It's a pre-installed app with a market update installed 
    } 
} 
+0

謝謝主席先生! – ComputerSaysNo

相關問題