Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

android - Cannot resolve Manifest.permission.ACCESS_FINE_LOCATION

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...