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 PackageInfo getPackageInfo(Context context) {
    try {/*from w ww .  j a  va2 s . co m*/
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    } catch (NameNotFoundException e) {
        return null;
    }
}

From source file:Main.java

public static boolean TakeIsInstallApk(String abPath, Context context) {
    PackageManager pm = context.getPackageManager();
    try {//from   w  ww  .j  a va2s.  c  om
        pm.getPackageInfo(abPath, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static int getVersionCode(Context app) {
    PackageManager pm = app.getPackageManager();
    PackageInfo pi;/*from  www.j  a  v  a2  s .c o  m*/
    try {
        pi = pm.getPackageInfo(app.getPackageName(), 0);
        return pi.versionCode;
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }
}

From source file:Main.java

/**
 * Returns whether the device is an AndroidTV.
 *
 * @param context A context./*w ww. j  a  va2  s .  co m*/
 * @return True if the device is an AndroidTV. False otherwise.
 */
@SuppressLint("InlinedApi")
public static boolean isAndroidTv(Context context) {
    return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
}

From source file:Main.java

public static String getVersionName(Context app) {
    PackageManager pm = app.getPackageManager();
    PackageInfo pi;/*from w  w  w . j av  a  2  s .  com*/
    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 getLocalVersionName(Context context) {
    try {//from w  w w  . j  a v  a2  s.c om
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

private static boolean isPackageInstalled(String packagename, Context context) {
    PackageManager pm = context.getPackageManager();
    try {//from  w  ww  .  j ava2s . c  om
        pm.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   www  .java2s . co  m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        return 0;
    }
}

From source file:Main.java

public static String getAppVersionName(Context context) {
    PackageManager pm = context.getPackageManager();
    try {//from   w w w . j ava2 s .  c om
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        return pi == null ? "" : pi.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static String getAppVersionName(Context context) {
    try {//from   w ww.j  av  a  2 s .  co m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return "1.0.0";
}