get Package Name from apk file - Android App

Android examples for App:APK Information

Description

get Package Name from apk file

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 getPackageName(Context context, String filePath) {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo info = packageManager.getPackageArchiveInfo(filePath,
                PackageManager.GET_ACTIVITIES);
        if (info != null) {
            ApplicationInfo appInfo = info.applicationInfo;
            return appInfo.packageName;
        }//  ww w.j av a 2s  .c  om
        return null;
    }
}

Related Tutorials