Java tutorial
//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 ApplicationInfo getApplicationInfo(Context context) { if (context == null) { return null; } ApplicationInfo applicationInfo = null; try { applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return applicationInfo; } public static String getPackageName(Context context) { return getPackageInfo(context).packageName; } public static PackageInfo getPackageInfo(Context context) { PackageInfo pkg = null; if (context == null) { return null; } try { pkg = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return pkg; } }