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 Intent getLaunchAppIntent(Context context, String packageName) {
    return context.getPackageManager().getLaunchIntentForPackage(packageName);
}

From source file:Main.java

public static int getVersionCode(Context ctx) {
    try {//from  w w w .  j  a  va  2 s .c  om
        return ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode;
    } catch (Exception e) {
        return 0;
    }
}

From source file:Main.java

/**
 * Used to determine if the current device is a Google TV
 * /*from  w ww  .  j  a  va  2 s.  c o  m*/
 * @param context The {@link Context} to use
 * @return True if the device has Google TV, false otherwise
 */
public static final boolean isGoogleTV(final Context context) {
    return context.getPackageManager().hasSystemFeature("com.google.android.tv");
}

From source file:Main.java

public static List<PackageInfo> getInstalledPackages(Context context) {
    PackageManager pm = context.getPackageManager();
    List<PackageInfo> infos = pm.getInstalledPackages(0);
    return infos;
}

From source file:Main.java

public final static boolean isInstall(String pkg, Context ctx) {
    PackageManager pm = ctx.getPackageManager();
    try {/*w w w . ja  va 2  s .com*/
        pm.getPackageInfo(pkg, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static boolean isAPKFileValid(String path, Context context) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pi = pm.getPackageArchiveInfo(path, 0);

    return pi != null;
}

From source file:Main.java

static boolean hasPermission(Context context, String permission) {
    return (context.getPackageManager().checkPermission(permission,
            context.getPackageName()) == PackageManager.PERMISSION_GRANTED);
}

From source file:Main.java

public static boolean hasMessengerInstalled(Context context) {
    try {/*w ww .j  av a2 s.c  om*/
        context.getPackageManager().getPackageInfo("com.facebook.orca", 0);
        return true;
    } catch (PackageManager.NameNotFoundException var0_1) {
        return false;
    }
}

From source file:Main.java

public static boolean checkCameraAvailability(Context context) {
    PackageManager pm = context.getPackageManager();

    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        return true;
    }//from   w ww. j  a v a2 s  .  c o m

    return false;
}

From source file:Main.java

public static boolean checkCameraHardware(Context context) {
    if (context != null && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        return true;
    } else {/*from   w w w . j  a  v  a 2 s . com*/
        return false;
    }
}