2017-08-04 87 views

回答

0
List<ApplicationInfo> packages = context.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA); 
for (ApplicationInfo packageInfo : packages) { 
    Log.d(TAG, "Package :" + packageInfo.packageName); 
    Log.d(TAG, "Launcher Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
} 

ApplicationInfo由具有的packageName字段,其​​提供打包的應用程序的名稱。

0

您可以使用下面的代碼來獲得系統應用PackageInfo名單,

public static ArrayList<PackageInfo> getSystemPackageInfos(final Activity context) { 
    ArrayList<PackageInfo> list = new ArrayList<PackageInfo>(); 
    ArrayList<String> packageNames = new ArrayList<String>(); 
    PackageManager pm = context.getPackageManager(); 
    List<PackageInfo> pinfoList = pm.getInstalledPackages(0); 
    Collections.sort(pinfoList, PackageNameComparator); 

    for (PackageInfo pinfo : pinfoList) { 
     packageNames.add(pinfo.packageName); 
     boolean isSystem = false; 

     if (((pinfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)) { 
      isSystem = false; 
     } else { 
      isSystem = true; 
     } 

     if (pinfo.applicationInfo.sourceDir.startsWith("/data/app/") && isSystem) { 
      //Non-system app 
      isSystem = false; 
     } 

     if (!isSystem) { 
      continue; 
     } 

     Bitmap icon = null; 
     Drawable apkIcon = getApplicationIcon(pinfo.applicationInfo, context); 
     try { 
      icon = Bitmap.createBitmap(apkIcon.getIntrinsicWidth(), apkIcon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); 

      Canvas canvas = new Canvas(icon); 
      apkIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); 
      apkIcon.draw(canvas); 
     } catch (ClassCastException e) { 
     } 
     String name = pinfo.applicationInfo.loadLabel(pm).toString(); 

     long apkSize = new File(pinfo.applicationInfo.sourceDir).length(); 


     list.add(pinfo); 

    } 
    return list; 
} 
相關問題