Example usage for android.content Context getPackageManager

List of usage examples for android.content Context getPackageManager

Introduction

In this page you can find the example usage for android.content Context getPackageManager.

Prototype

public abstract PackageManager getPackageManager();

Source Link

Document

Return PackageManager instance to find global package information.

Usage

From source file:Main.java

public static String getVersion(Context context) {
    PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> packageInfoList = packageManager.getInstalledPackages(0);

    for (PackageInfo packageInfo : packageInfoList) {
        if ("com.tencent.mm".equals(packageInfo.packageName)) {
            return packageInfo.versionName;
        }// w  w  w  . j a va 2s.  co m
    }
    return "6.3.25";
}

From source file:Main.java

private static boolean isAppInstalled(Context context, String packageName) {
    try {/*w ww  .  j  av a  2  s  . c  o  m*/
        context.getPackageManager().getPackageInfo(packageName, 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static boolean isPackageExist(Context context, String packageName) {
    try {//from   w  w w .  ja va  2s.com
        context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static boolean isAppInstalled(Context context, String packageName) {
    try {/* w  ww.j  ava  2  s  .co m*/
        context.getPackageManager().getPackageInfo(packageName, 0);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {//from w  ww . j a  v a2  s  .  co  m

        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return info.versionCode;
    } catch (NameNotFoundException e) {
        return 0;
    }
}

From source file:Main.java

public static int getAppVersionCode(Context context) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pi;/*w  w w.  j  av a  2 s  . c  o  m*/
    try {
        pi = pm.getPackageInfo(context.getPackageName(), 0);
        return pi.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static String getPackageVersionName(Context context) throws PackageManager.NameNotFoundException {
    return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
}

From source file:Main.java

public static String getAppMetaData(Context context, String key) {
    try {/*from   w ww.j  av  a2 s. c  o  m*/
        return context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA).metaData.getString(key);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {/*from   w ww  .j  a v  a2 s .com*/
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
    }
    return -1;
}

From source file:Main.java

public static PackageInfo getApkInfo(Context context, String pkg) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pkgInfo = null;// ww  w  . j a va  2s  .  c  om
    try {
        pkgInfo = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return pkgInfo;
}