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 int getVersionCode(Context app) {
    PackageManager pm = app.getPackageManager();
    PackageInfo pi;//from   w w w .  j av a  2  s.  co m
    try {
        pi = pm.getPackageInfo(app.getPackageName(), 0);
        return pi.versionCode;
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }
}

From source file:Main.java

public static String getVersionName(Context app) {
    PackageManager pm = app.getPackageManager();
    PackageInfo pi;//from www . j a v  a  2s  .  co  m
    try {
        pi = pm.getPackageInfo(app.getPackageName(), 0);
        return pi.versionName;
    } catch (Exception e) {
        e.printStackTrace();
        return app.getPackageName();
    }
}

From source file:Main.java

public static String getAPPName(Context context) {
    try {/*from  w ww .  j a va2  s .c  om*/
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        int labelRes = packageInfo.applicationInfo.labelRes;
        return context.getResources().getString(labelRes);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {/*from ww w .j a  va  2s .  c  o m*/
        PackageManager manager = context.getPackageManager();
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        int version = info.versionCode;
        return version;
    } catch (Exception e) {
        e.printStackTrace();
        return GET_VERSION_WRONG;
    }

}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {/* w w  w  . ja  va  2 s.  c  om*/
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionCode;

    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return -1;
}

From source file:Main.java

public static String getVersion(Context context) {
    try {//from   ww  w . j  ava 2 s.c om
        PackageManager manager = context.getPackageManager();
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        String version = info.versionName;
        return version;
    } catch (Exception e) {
        e.printStackTrace();
        return "1.0";
    }
}

From source file:Main.java

public static int getAppVersionCode(Context context) {
    int appVersionCode = 0;
    try {/*from   w w w  . j  av a  2  s  .  c o  m*/
        PackageManager manager = context.getPackageManager();
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        appVersionCode = info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e("SysUtils", e.getMessage());
    }
    return appVersionCode;
}

From source file:Main.java

public static String getVersionName(Context context) {
    PackageManager pm = context.getPackageManager();
    try {/*from   ww w .j  a  va2  s  . c  o  m*/
        PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
        if (packageInfo != null) {
            return packageInfo.versionName;
        }
    } catch (PackageManager.NameNotFoundException e) {
    } catch (RuntimeException e) {
    }
    return null;
}

From source file:Main.java

public static Boolean isAppInstalled(Context context, String appName) {
    PackageManager pm = context.getPackageManager();
    boolean installed;
    try {//  ww  w  .  j  a  v  a  2 s.co m
        pm.getPackageInfo(appName, PackageManager.GET_ACTIVITIES);
        installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        installed = false;
    }
    return installed;
}

From source file:Main.java

public static boolean isAppInstalled(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    boolean installed;
    try {/*  ww w  . ja  v a 2  s  .  c  o  m*/
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        installed = false;
    }
    return installed;
}