get Apk Meta Data - Android android.content.pm

Android examples for android.content.pm:Apk Property

Description

get Apk Meta Data

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 getApkMetaData(Context context, String apkPath, String key) {

    if (context == null || key == null) {
      return null;
    }//from  w w w . j a  v a  2  s . c  o  m

    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_META_DATA);
    if (info != null) {
      ApplicationInfo appInfo = info.applicationInfo;

      if (appInfo == null || appInfo.metaData == null) {
        return null;
      }

      return appInfo.metaData.getString(key);
    }

    return null;
  }

}

Related Tutorials