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 int getAppVerCode(Context c) {
    try {/*from w w  w  .j a  v a2s  . c o  m*/
        PackageInfo packageInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
        return packageInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        return 0;
    }
}

From source file:Main.java

public static boolean isAppInstalled(Context context, String packageName) {
    try {//w w w. j av  a2s  .  com
        context.getPackageManager().getPackageInfo(packageName, 0);
        return true;
    } catch (Exception ignored) {
        return false;
    }
}

From source file:Main.java

public static int getAppVersion(Context context) {
    try {/*w  ww .java 2  s. c o  m*/
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return info.versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return 1;
}

From source file:Main.java

public static String getAppVer(Context c) {
    try {/*from w  ww  .  jav a2 s .  c  o  m*/
        PackageInfo packageInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
        return packageInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        return "";
    }
}

From source file:Main.java

public static boolean isGoogleTV(Context context) {
    PackageManager packageManager = context.getPackageManager();
    return packageManager != null && packageManager.hasSystemFeature("com.google.android.tv");
}

From source file:Main.java

/**
 * get list of app//w ww. j a  va2 s  . com
 *
 * @param context
 * @return
 */
public static List<PackageInfo> getPackageInfos(Context context) {
    PackageManager pm = context.getPackageManager();
    List<PackageInfo> appInfos = pm.getInstalledPackages(0);
    return appInfos;
}

From source file:Main.java

public static PackageInfo getApkInfo(Context context, String archiveFilePath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo apkInfo = pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_META_DATA);
    return apkInfo;
}

From source file:Main.java

public static void turnOffFlash(Context context, Camera camera, int currentCameraId) {
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
        Parameters params = camera.getParameters();
        params.setFlashMode(Parameters.FLASH_MODE_OFF);
        camera.setParameters(params);/* ww w .  ja  v a  2  s .  c om*/
    }
}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {/*  ww w. j ava  2 s  .c o m*/
        PackageInfo pkg = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return pkg.versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static String getPackageName(Context contex) {
    PackageManager manager = contex.getPackageManager();
    try {/*w w  w .j  a v a 2  s.c  om*/
        PackageInfo info = manager.getPackageInfo(contex.getPackageName(), 0);
        return info.packageName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}