Java tutorial
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; public class Main { /** * Retrieves the PackageInfo object for this application. * * @param context Any context. * @return The PackageInfo object for this application. */ public static PackageInfo getOwnPackageInfo(Context context) { PackageManager manager = context.getPackageManager(); try { String packageName = context.getApplicationContext().getPackageName(); return manager.getPackageInfo(packageName, 0); } catch (NameNotFoundException e) { // Should never happen. throw new AssertionError("Failed to retrieve own package info"); } } }