无法解析 Manifest.permission.ACCESS_FINE_LOCATION [英] Cannot resolve Manifest.permission.ACCESS_FINE_LOCATION
问题描述
向我的清单文件添加权限时,以下 xml 有效.
When adding permissions to my manifest file, the below xml works.
<permission android:name="android.permission.ACCESS_FINE_LOCATION" />
然而,这个 xml 不起作用.
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?
此外,我收到了与 Android 6.0 运行时权限相关的异常:
Also, I am getting an Android 6.0 runtime permissions related exception:
java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
当我尝试将权限添加到字符串数组以检查权限时,Android Studio 告诉我它无法解析以下代码中的 Manifest.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?
推荐答案
对于第一部分,您应该使用
根据 Android 开发者网站.尝试确保在
标签下直接声明你的权限,而不是在你的
标签中.如果不查看整个清单文件,很难知道您的问题是什么.查看我上面发布的链接,了解有关如何在您的清单.
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..
新字符串[]{Manifest.permission.ACCESS_FINE_LOCATION}
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}
为什么?
确保您使用的是 android.Manifest
而不是 my.app.package.Manifest
.很多时候 Android Studio 会默认使用后者而不是前者.
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};
我重新格式化了答案.
编辑 2:小心导入 android.Manifest
.如果您还导入 my.app.package.Manifest
,可能 会导致问题.除此之外,import android.Manifest
是解决此问题的另一种有效方法.
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屋!