即使在清单中设置了权限,权限异常也是如此 [英] Permission exception even though permission is set in manifest

查看:237
本文介绍了即使在清单中设置了权限,权限异常也是如此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的清单中,我有:

 <使用权限android:name =android.permission.ACCESS_FINE_LOCATION/ > 

但是,当我运行我的应用程序并按下需要此权限的按钮时,出现以下异常:

 地理栅栏使用需要ACCESS_FINE_LOCATION权限

我该如何解决这个问题?



我有< manifest>

我使用Android 6.



这是我的代码:

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


尝试{
LocationServices.GeofencingApi.addGeofences(
mGoogleApiClient,
// GeofenceRequest对象。
getGeofencingRequest(),
//当调用removeGeofences()时被重用的未决意图
//待定意图用于在观察到匹配的geofence
//转换时生成意图
getGeofencePendingIntent()
).setResultCallback(this); //在onResult()中处理结果。
} catch(SecurityException securityException){
//如果应用程序未使用ACCESS_FINE_LOCATION权限,则捕获异常。
logSecurityException(securityException);
}
}


解决方案

编译API 23你必须要求这个权限。



这是一篇很好的博客文章: http://android-developers.blogspot.de/2015/09/google-play-services-81-and-android-60.html


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);
        }
    }

解决方案

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

这篇关于即使在清单中设置了权限,权限异常也是如此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆