Example usage for android.content.pm PackageManager checkPermission

List of usage examples for android.content.pm PackageManager checkPermission

Introduction

In this page you can find the example usage for android.content.pm PackageManager checkPermission.

Prototype

@CheckResult
public abstract @PermissionResult int checkPermission(String permName, String pkgName);

Source Link

Document

Check whether a particular package has been granted a particular permission.

Usage

From source file:Main.java

public static boolean checkPermission(Context context, String paramString) {
    PackageManager localPackageManager = context.getPackageManager();
    return localPackageManager.checkPermission(paramString, context.getPackageName()) == 0;
}

From source file:Main.java

/**
 * @param context/*from  w  w  w  .j a  v a 2  s.  c o m*/
 * @return Boolean
 * @throws
 * @Title: checkPhoneState
 * @Description: TODO
 */
private static Boolean checkPhoneState(Context context) {
    PackageManager pm = context.getPackageManager();
    if (pm.checkPermission("android.permission.READ_PHONE_STATE", context.getPackageName()) != 0) {
        return false;
    }
    return true;
}

From source file:Main.java

/**
 * @param context//  w w w . java2  s .  c  om
 * @param permission
 * @return boolean
 * @Title: checkPermission
 * @Description: TODO
 */
public static boolean checkPermission(Context context, String permission) {

    collectUtilContext = context;
    PackageManager pm = context.getPackageManager();
    return pm.checkPermission(permission,
            collectUtilContext.getPackageName()) == PackageManager.PERMISSION_GRANTED;
}

From source file:Main.java

public static boolean checkPermission(Context context, String permission) {
    boolean result = false;
    if (Build.VERSION.SDK_INT >= 23) {
        try {//from  w ww.ja  v  a2 s  .c o m
            Class<?> clazz = Class.forName("android.content.Context");
            Method method = clazz.getMethod("checkSelfPermission", String.class);
            int rest = (Integer) method.invoke(context, permission);
            result = rest == PackageManager.PERMISSION_GRANTED;
        } catch (Exception e) {
            result = false;
        }
    } else {
        PackageManager pm = context.getPackageManager();
        if (pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
            result = true;
        }
    }
    return result;
}

From source file:Main.java

public static boolean getPermission(String permission, Context context) {
    PackageManager pm = context.getPackageManager();
    return PackageManager.PERMISSION_GRANTED == pm.checkPermission(permission, "com.example.renrenstep");
}

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 checkPermission(Context context, String packName, String permissionName) {
    PackageManager pm = context.getPackageManager();
    return (PackageManager.PERMISSION_GRANTED == pm.checkPermission(permissionName, packName));
}

From source file:Main.java

public static boolean checkPermission(Context context, String permission) {
    boolean result = false;
    if (Build.VERSION.SDK_INT >= 23) {
        try {// w  w w. jav a  2 s.co  m
            Class<?> clazz = Class.forName("android.content.Context");
            Method method = clazz.getMethod("checkSelfPermission", String.class);
            int rest = (Integer) method.invoke(context, permission);
            if (rest == PackageManager.PERMISSION_GRANTED) {
                result = true;
            } else {
                result = false;
            }
        } catch (Exception e) {
            result = false;
        }
    } else {
        PackageManager pm = context.getPackageManager();
        if (pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
            result = true;
        }
    }
    return result;
}

From source file:Main.java

public static boolean checkPermission(Context context, String permName, String pkgName) {
    PackageManager pm = context.getPackageManager();
    if (PackageManager.PERMISSION_GRANTED == pm.checkPermission(permName, pkgName)) {
        //            System.out.println(pkgName + "has permission : " + permName);
        return true;
    } else {/*w w w. ja  v a2  s.  c  om*/
        //PackageManager.PERMISSION_DENIED == pm.checkPermission(permName, pkgName)
        //            System.out.println(pkgName + "not has permission : " + permName);
        return false;
    }
}

From source file:Main.java

public static boolean isBlePermission(Context context) {
    PackageManager pm = context.getPackageManager();
    boolean permission = (PackageManager.PERMISSION_GRANTED == pm
            .checkPermission("android.permission.BLUETOOTH", context.getPackageName()));
    return permission;
}