Example usage for android.content.pm PackageManager PERMISSION_GRANTED

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

Introduction

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

Prototype

int PERMISSION_GRANTED

To view the source code for android.content.pm PackageManager PERMISSION_GRANTED.

Click Source Link

Document

Permission check result: this is returned by #checkPermission if the permission has been granted to the given package.

Usage

From source file:Main.java

public static boolean hasVibrationPermission(Context context) {
    // temporary workaround until https://github.com/robolectric/robolectric/pull/2047 is released
    try {//  ww  w . j  av a 2  s .c  om
        return (context.getPackageManager().checkPermission(Manifest.permission.VIBRATE,
                context.getPackageName()) == PackageManager.PERMISSION_GRANTED);
    } catch (NullPointerException e) {
        return false;
    }
}

From source file:Main.java

public static boolean checkPermission(Context context, String permission) {
    int res = context.checkCallingOrSelfPermission(permission);
    return (res == PackageManager.PERMISSION_GRANTED);
}

From source file:cat.mvmike.minimalcalendarwidget.activity.PermissionsActivity.java

public static boolean isPermitted(final Context context) {
    return ContextCompat.checkSelfPermission(context,
            Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED;
}

From source file:Main.java

/**
 * Returns true if the context has permission to access the network state and
 * access the internet./*from w ww .j ava  2 s .  c  om*/
 * 
 * @return True if the context has the correct permissions.
 */
public static boolean hasNetworkPermissions(Context context) {

    // get permissions for accessing the internet and network state
    int internetPerm = context.checkCallingOrSelfPermission(Manifest.permission.INTERNET);
    int networkStatePerm = context.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE);

    // are those permissions allowed
    boolean internetAllowed = internetPerm == PackageManager.PERMISSION_GRANTED;
    boolean networkAllowed = networkStatePerm == PackageManager.PERMISSION_GRANTED;

    // if they are check if we are connected to the network
    return (internetAllowed && networkAllowed);
}

From source file:Main.java

public static boolean checkPermissionGranted(String p, Context c) {
    return c.checkCallingOrSelfPermission(p) == PackageManager.PERMISSION_GRANTED;
}

From source file:Main.java

public static boolean permissionGranted(int requestCode, int permissionCode, int[] grantResults) {
    if (requestCode == permissionCode) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            return true;
        } else {//  ww w. j a  v  a 2  s.  co m
            return false;
        }
    }
    return false;
}

From source file:Main.java

public static boolean hasVibratePermission(Context context) {
    int res = context.checkCallingOrSelfPermission(Manifest.permission.VIBRATE);
    return (res == PackageManager.PERMISSION_GRANTED);
}

From source file:Main.java

/**
 * @param grantResults array as received by onRequestPermissionsResult
 * @return true if all granted, false otherwise.
 *//*from  ww  w. ja  v  a2s.c  o  m*/
public static boolean allPermissionsGranted(int[] grantResults) {
    for (int i = 0; i < grantResults.length; ++i) {
        if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * @param context//from  w  ww .ja va 2 s .c o  m
 * @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

/**
 * Checks whether permission allow by user.
 * @param context context of application
 * @return Returns true if permission allow, otherwise false
 *//*from w w  w .  j  a  v a2s  .c om*/
public static boolean isBLEPermission(final Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return true;
    } else {
        boolean result = true;
        for (int i = 0; i < BLE_PERMISSIONS.length; i++) {
            if (context.checkSelfPermission(BLE_PERMISSIONS[i]) != PackageManager.PERMISSION_GRANTED) {
                result = false;
            }
        }
        return result;
    }
}