Example usage for android.content.pm PackageManager getPackageInfo

List of usage examples for android.content.pm PackageManager getPackageInfo

Introduction

In this page you can find the example usage for android.content.pm PackageManager getPackageInfo.

Prototype

public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags)
        throws NameNotFoundException;

Source Link

Document

Retrieve overall information about an application package that is installed on the system.

Usage

From source file:Main.java

public static String getVersioName(Context context) {
    try {/*  w  ww.  ja v a 2s. c o m*/
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionName;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static int getVersionCode(Context context) {
    PackageManager manager = context.getPackageManager();
    try {// www .  j a  va 2 s . co  m
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        return info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    return 0;
}

From source file:Main.java

private static boolean isPackageInstalled(Context context, String pkgName) {
    PackageManager pm = context.getPackageManager();
    try {//from  w  w w.  ja v  a2  s . c  o m
        PackageInfo pkgInfo = pm.getPackageInfo(pkgName, 0);
        return pkgInfo != null && pkgInfo.applicationInfo.enabled;
    } catch (PackageManager.NameNotFoundException e) {
    }
    return false;
}

From source file:Main.java

public static int getVersioCode(Context context) {
    try {/*from   w  ww  .  j  a va 2 s  .  c  om*/
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionCode;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return -1;
}

From source file:Main.java

public static String getVersionName(Context context) {
    String versionName = "";
    try {/*  www.  jav a  2s .c  o m*/
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        versionName = packInfo.versionName;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return versionName;
}

From source file:Main.java

public static String getAppName(Context context) {
    try {/*from w  w  w . j ava  2  s  .com*/
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        int labelRes = packageInfo.applicationInfo.labelRes;
        return context.getResources().getString(labelRes);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static boolean isPackageAvailable(final Context context, final String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    try {/*from  w  ww .  ja v  a  2 s.c  o m*/
        packageManager.getPackageInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
        return true;
    } catch (final NameNotFoundException exception) {
        return false;
    }
}

From source file:Main.java

/**
 * Check if BerryMotes app is installed 
 * //from  www  . j a  v a2  s  .c  om
 * @param context Android context
 * @return true if BerryMotes is installed
 */
public static boolean isBerryMotesInstalled(Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo(BERRYMOTES_NAME, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static String getAppName(Context context) {
    try {//  ww  w.j a  v  a  2s  .c  om
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        int labelRes = packageInfo.applicationInfo.labelRes;
        return context.getResources().getString(labelRes);
    } catch (PackageManager.NameNotFoundException e) {
    }
    return null;
}

From source file:Main.java

public static int getVersionCode(Context context) {
    PackageManager pm = context.getPackageManager();
    try {/*  w  w w  .java2 s  .  c o m*/
        PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}