Android权限检查无法识别

时间:2016-03-13 15:03:59

标签: android android-permissions

我正在尝试访问Android 23中的s = s.replace()

我创建了一个FusedLocationApi类,它有一些方法可以检查是否授予了权限。

PermissionUtils

在片段中,我正在调用public class PermissionUtils { private static abstract class AbstractPermission { public static boolean check(Context context, String permission) { return (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED); } /** * Requests the permission. If a rationale with an additional explanation should * be shown to the user, displays a dialog that triggers the request. */ public static void request(Activity activity, int requestId, String permission) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { // TODO - Display a dialog with rationale. ActivityCompat.requestPermissions(activity, new String[]{permission}, requestId); } else { // Location permission has not been granted yet, request it. ActivityCompat.requestPermissions(activity, new String[]{permission}, requestId); } } } public static final class FineLocation { private static final String permission = Manifest.permission.ACCESS_FINE_LOCATION; private static final String permissionCellTowerPrecision = Manifest.permission.ACCESS_COARSE_LOCATION; private static final int requestId = PermissionCodes.LOCATION_PERMISSION_REQUEST_CODE; public static boolean check(Context context) { return AbstractPermission.check(context, permission) && AbstractPermission.check(context, permissionCellTowerPrecision); } public static void request(Activity activity) { AbstractPermission.request(activity, requestId, permission); } } }

FineLocation.check()

问题是我仍然收到错误:protected void startLocationUpdates() { if (PermissionUtils.FineLocation.check(getActivity())) { PermissionUtils.FineLocation.request(getActivity()); } else { LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); } }

我如何告诉检查员我已检查过许可?

1 个答案:

答案 0 :(得分:0)

因此,问题是Inspector无法识别我正在检查权限。 代码编译正常,应用程序可以安装在USB设备或仿真器上。

您可以转到:

切换检查的严重性

Settings > Editor > Inspections > Android > Constant and Resource Type Mismatches

严重性默认为error。您可以将其设置为warning,以便它仍会宣布您,这样您就可以确定是否正在检查权限。