2013-02-19 72 views
0

我已經嘗試了我粘貼在下面的代碼..但是這給了我安裝的每個應用程序,但然後我需要檢查每個應用程序是否是我的或不通過檢查包名稱...是有一個代碼,我可以將包名稱傳遞給電話系統,以便它可以根據該包名稱安裝所有應用程序。從軟件包名稱中獲得已安裝的應用程序

PackageManager manager = getPackageManager(); 
     Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
     mainIntent.addCategory(Intent.CATEGORY_DEFAULT); 
     final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0); 
     Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager)); 
     ArrayList<String> oArrInstalledHomeApps = new ArrayList<String>(); 
     if (apps != null) 
     { 
      final int count = apps.size(); 

      for (int i = 0; i < count; i++) 
      { 
       ResolveInfo info = apps.get(i); 
       String strpackageName = info.activityInfo.applicationInfo.packageName; 
if(strpackageName.contains ("com.ZZ.")) 
{ 
       oArrInstalledHomeApps.add(strpackageName); 
} 
      } 
      return oArrInstalledHomeApps; 
     } 
+1

[基於包名GetInstalled應用]的可能重複(http://stackoverflow.com/questions/14955232/getinstalled-apps-based-on-package-name無恥複製) – 2013-02-19 10:45:03

+1

請不要一再提出同樣的問題。 – 2013-02-19 10:45:14

+0

該帖子已被刪除:( – user1340801 2013-02-19 10:50:50

回答

2

這是一個更清潔的方式來做到這一點。

final PackageManager pm = getPackageManager(); 
     ArrayList<String> oArrInstalledHomeApps = new ArrayList<String>(); 
     // get a list of installed apps. 
     List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); 
     for (ApplicationInfo packageInfo : packages) 
     { 
      Log.d(TAG, "Installed package :" + packageInfo.packageName); 
      Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
      if (packageInfo.packageName.contains("com.ZZ.")) 
      { 
       oArrInstalledHomeApps.add(packageInfo.packageName); 
      } 
     } 
     return oArrInstalledHomeApps; 

從這個link

+0

這就是我的整點上述代碼獲取所有安裝的應用程序,然後檢查我的包...這需要時間..所以我怎麼樣發送我的軟件包名稱和電話給我回安裝的應用程序.. – user1340801 2013-02-19 10:55:02

+0

@ user1340801你不能這樣做Android在PackageManager中沒有像那樣的搜索過濾器 – 2013-02-19 10:55:35

+0

@RaghavSood謝謝..那是我想了解的!!!!! ..所以我需要得到所有的應用程序,並檢查我的包?? /它需要5-7秒額外 – user1340801 2013-02-19 10:58:39

相關問題