Permission exception even though permission is set in manifest [duplicate]

江枫思渺然 提交于 2019-12-19 11:39:31

问题


In my manifest I have:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

However, when I run my app and press the button that needs this permission I get the following exception:

Geofence usage requires ACCESS_FINE_LOCATION permission

How can I fix this?

I have the permission right under <manifest>

I am using Android 6.

This is my code:

   public void addGeofencesButtonHandler(View view) {
        if (!mGoogleApiClient.isConnected()) {
            Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show();
            return;
        }

        try {
            LocationServices.GeofencingApi.addGeofences(
                    mGoogleApiClient,
                    // The GeofenceRequest object.
                    getGeofencingRequest(),
                    // A pending intent that that is reused when calling removeGeofences(). This
                    // pending intent is used to generate an intent when a matched geofence
                    // transition is observed.
                    getGeofencePendingIntent()
            ).setResultCallback(this); // Result processed in onResult().
        } catch (SecurityException securityException) {
            // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission.
            logSecurityException(securityException);
        }
    }

回答1:


When compiling for API 23 you have to ask for that Permission.

Theres a good Blog Post about that: http://android-developers.blogspot.de/2015/09/google-play-services-81-and-android-60.html



来源:https://stackoverflow.com/questions/33317195/permission-exception-even-though-permission-is-set-in-manifest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!