content: package io.alcatraz.audiohq.utils;
  
  import android.content.Context;
  import android.content.pm.ApplicationInfo;
  import android.content.pm.PackageInfo;
  import android.content.pm.PackageManager;
  import android.graphics.drawable.Drawable;
  
  public class PackageCtlUtils {
      public static Drawable getIcon(Context ctx, String pkg) {
          PackageManager pm = ctx.getPackageManager();
          try {
              ApplicationInfo ai = pm.getApplicationInfo(pkg, PackageManager.GET_META_DATA);
              return pm.getApplicationIcon(ai);
          } catch (PackageManager.NameNotFoundException e) {
              return null;
          }
      }
  
      public static Drawable getIcon(Context ctx, ApplicationInfo info) {
          PackageManager pm = ctx.getPackageManager();
          return pm.getApplicationIcon(info);
      }
  
      public static String getLabel(Context ctx, String pkg) {
          PackageManager pm = ctx.getPackageManager();
          try {
              ApplicationInfo ai = pm.getApplicationInfo(pkg, PackageManager.GET_META_DATA);
              return pm.getApplicationLabel(ai).toString();
          } catch (PackageManager.NameNotFoundException e) {
              return pkg;
          }
      }
  
      public static String getLabel(Context ctx, ApplicationInfo info){
          PackageManager pm = ctx.getPackageManager();
          return pm.getApplicationLabel(info).toString();
      }
  
      public static synchronized String getVersionName(Context context) {
          try {
              PackageManager packageManager = context.getPackageManager();
              PackageInfo packageInfo = packageManager.getPackageInfo(
                      context.getPackageName(), 0);
              return packageInfo.versionName;
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;
      }
  
      public static synchronized int getVersionCode(Context context) {
          try {
              PackageManager packageManager = context.getPackageManager();
              PackageInfo packageInfo = packageManager.getPackageInfo(
                      context.getPackageName(), 0);
              return packageInfo.versionCode;
          } catch (Exception e) {
              e.printStackTrace();
          }
          return 0;
      }
  }
  