@PermissionChecker.PermissionResult
注释的想法是什么?
我有一个需要一些许可的方法:
@RequiresPermission(Manifest.permission_group.LOCATION)
private void startLocationUpdates() { ... }
但是当我检查onRequestPermissionsResult
函数中的权限时,它会警告我需要
public abstract class PermissionUtil {
/**
* Check that all given permissions have been granted by verifying that each entry in the
* given array is of the value {@link PackageManager#PERMISSION_GRANTED}.
*
* @see Activity#onRequestPermissionsResult(int, String[], int[])
*/
@PermissionChecker.PermissionResult
public static boolean verifyPermissions(int[] grantResults) {
// At least one result must be checked.
if (grantResults.length < 1) {
return false;
}
// Verify that each required permission has been granted, otherwise return false.
for (int i = 0, size = grantResults.length; i < size; i++) {
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
}
...
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode == CODE_PERMISSIONS_LOCATION) {
if (PermissionUtil.verifyPermissions(grantResults)) {
startLocationUpdates(); /// WARNING!!
检查/// WARNING!!
行,不应该有警告,因为它已经被授予......
已经尝试过使用@PermissionChecker.PermissionResult
注释,重点是什么?如何添加RequiresPermission
并在此处查看?