get Apk Package Name - Android android.content.pm

Android examples for android.content.pm:Apk Property

Description

get Apk Package Name

Demo Code

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import java.io.File;

public class Main{

    public static String getApkPackageName(Context context, String apkPath) {

        if (context == null || apkPath == null) {
            return null;
        }//from  w  w w.  jav a  2 s. co m

        PackageManager pm = context.getPackageManager();
        PackageInfo info = pm.getPackageArchiveInfo(apkPath,
                PackageManager.GET_ACTIVITIES);
        if (info != null) {
            ApplicationInfo appInfo = info.applicationInfo;
            String appName = pm.getApplicationLabel(appInfo).toString();
            String packageName = appInfo.packageName; 

            return packageName;
        }

        return null;
    }

}

Related Tutorials