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 boolean appInstalledOrNot(Context context, String packageName) {
    try {//w w w.  j  a v a 2  s .com
        context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {//from   w ww  .jav  a 2  s . c om
        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return pi.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        return 0;
    }
}

From source file:Main.java

public static boolean isInstalled(Context context, String packageName) {
    try {/*from  www  .ja  v  a  2s.c o m*/
        context.getPackageManager().getPackageInfo(packageName, 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static int getCurrentApkReleaseVersion(Context context) {
    try {//from  ww w.  java 2  s. co m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        throw new AssertionError(e);
    }
}

From source file:Main.java

public static String getVersionName(Context ctx) {
    try {/*from  www  . j  a  v a 2 s.com*/
        PackageInfo packInfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
        return packInfo.versionName;
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
}

From source file:Main.java

/**
 * Retrieves the PackageInfo object for this application.
 *
 * @param context Any context.//from w  w w  . ja  va 2  s.c  o  m
 * @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");
    }
}

From source file:Main.java

public static boolean isPackageInstall(Context context, String packageName) {
    try {/*w  w w  . java2 s  . c  o  m*/
        context.getPackageManager().getApplicationInfo(packageName, 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static boolean IsAppInstalled(Context context, String packageName) {
    try {/*from  w ww . ja v a  2 s  . c  o  m*/
        context.getPackageManager().getApplicationInfo(packageName, 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

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

From source file:Main.java

public static int getAppVerCode(Context ctx) {
    try {/*  w  ww .ja v a  2 s .  c  om*/
        PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(),
                PackageManager.GET_CONFIGURATIONS);
        return info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}