get Apk Label - Android android.content.pm

Android examples for android.content.pm:Apk Property

Description

get Apk Label

Demo Code

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Main {

  public static String getApkLable(Context context, String apkPath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
    String lable = null;//from  w  w  w  . j a va 2  s .c o m
    if (info != null) {
      ApplicationInfo appInfo = info.applicationInfo;
      appInfo.sourceDir = apkPath;
      appInfo.publicSourceDir = apkPath;
      try {
        lable = pm.getApplicationLabel(appInfo).toString();

      } catch (OutOfMemoryError e) {
        lable = null;
      }
    }
    return lable;
  }

}

Related Tutorials