无法解析Manifest.permission.ACCESS_FINE_LOCATION [英] Cannot resolve Manifest.permission.ACCESS_FINE_LOCATION

查看:248
本文介绍了无法解析Manifest.permission.ACCESS_FINE_LOCATION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < permission android:name =android。

permission.ACCESS_FINE_LOCATION/>

但是,这个xml不起作用。

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

我应该使用哪一个?如果它是第一个,为什么它不起作用?如何修复它?



另外,我得到一个Android 6.0运行时权限相关的异常:

  java.lang.SecurityException:gps位置提供程序需要ACCESS_FINE_LOCATION权限。 

当我尝试将权限添加到字符串数组以检查权限时,Android Studio会告诉我不能在下面的代码中解决 Manifest.permission

  new String [] {Manifest.permission.ACCESS_FINE_LOCATION} 

为什么会这样做?我该如何解决这个问题?

第二部分,你应该使用< uses-权限> 根据Android Devlopers网站 。请务必确保您在< manifest> 标签下直接声明了直接的权限,而不是在< application> / code>标签。如果没有看到您的整个清单文件,很难知道您的问题。 查看我上面发布的链接,了解有关如何在您的应用中声明权限的更多信息清单。

关于您的运行时权限问题:


With uses-权限无法解决..



new String [] {Manifest.permission.ACCESS_FINE_LOCATION}



为什么? / p>

确保您使用 android.Manifest 而不是 my.app.package.Manifest 。很多时候,Android Studio会默认使用后者而不是前者。



因此,您的新代码行如下所示:

  new String [] {android.Manifest.permission.ACCESS_FINE_LOCATION}; 

编辑:我重新格式化了我的答案。

编辑2:谨慎导入 android.manifest 。如果您还要导入 my.app.package.Manifest ,它会导致问题。除此之外导入android.Manifest 是解决此问题的另一种有效方法。


When adding permissions to my manifest file, the below xml works.

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

However, this xml doesn't work.

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

Which one am I supposed to be using? If it's the first one, why wouldn't it work? How can I fix it?

Also, I am getting an Android 6.0 runtime permissions related exception:

java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.

When I try to add the permission to a String array in order to check the permission, Android Studio tells me it can't resolve Manifest.permission in the below code:

new String[]{Manifest.permission.ACCESS_FINE_LOCATION}

Why would it be doing this? How can I fix it?

解决方案

For the first part, you should be using <uses-permission> according the the Android Devlopers site. Try making sure you declare your permissions directly under the <manifest> tag, not in your <application> tag. It's hard to know what your problem is without seeing your entire manifest file. Check out the link I posted above for more info on how to declare permissions in your manifest.

In regards to your runtime permissions problem:

With uses-permissions Cannot resolve that..

new String[]{Manifest.permission.ACCESS_FINE_LOCATION}

Why?

Make sure you're using android.Manifest instead of my.app.package.Manifest. A lot of times Android Studio will default to the latter instead of the former.

So, your new line of code would look like:

new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION};

Edit: I reformatted my answer.

Edit 2: Be wary of importing android.Manifest. It can cause issues if you're also importing my.app.package.Manifest. Other than that import android.Manifest is another valid way to resolve this issue.

这篇关于无法解析Manifest.permission.ACCESS_FINE_LOCATION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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