get Apk Meta Data - Android App

Android examples for App:APK Information

Description

get Apk Meta Data

Demo Code


//package com.java2s;

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) {/*from   w  w  w. ja va 2 s  .c  o m*/

        if (context == null || key == null) {
            return null;
        }

        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