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 List<PackageInfo> getInstallPckInfo(Context context) {
    PackageManager pckMgr = context.getPackageManager();
    return pckMgr.getInstalledPackages(0);
}

From source file:Main.java

/**
 * get application directory//from www . j a v a  2s . c  om
 * @param context
 * @return {@link String}
 * @throws Exception
 */
public static String getAppDataDir(Context context) throws Exception {
    return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.dataDir;
}

From source file:Main.java

public static final int getVersion(Context ctx) {
    try {//w ww .j  av a 2  s .  com
        return ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

private static Intent getIntentByPackageName(Context context, String packageName) {
    return context.getPackageManager().getLaunchIntentForPackage(packageName);
}

From source file:Main.java

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

    pi.applicationInfo.sourceDir = path;
    pi.applicationInfo.publicSourceDir = path;
    return pi;/* ww  w  .ja va  2  s . c o m*/
}

From source file:Main.java

public static boolean gotHandlerForIntent(Context ctx, Intent intent) {
    return ctx.getPackageManager().resolveActivity(intent, 0) != null;
}

From source file:Main.java

public static boolean isPackageInstalled(String packageName, Context context) {
    PackageManager pm = context.getPackageManager();
    try {//from  www .j  a  v  a2s .com
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {//from  ww  w  .j  av a 2  s  . c  o m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

private static boolean checkPermission(Context context, String p) {
    PackageManager pm = context.getPackageManager();
    return (PackageManager.PERMISSION_GRANTED == pm.checkPermission(p, context.getPackageName()));
}

From source file:Main.java

public static boolean hasPermission(Context context, String permissionName) {
    return context.getPackageManager().checkPermission(permissionName, getPackageName(context)) == 0;
}