Android location permissions

喜夏-厌秋 提交于 2019-12-31 11:41:53

问题


In my Android application I'm willing to use GPS locations.

  1. What are the main permissions that I should included in android manifest file in order to use GPS locations.
  2. In case of lost the GPS signal strength, is there any way to triangulate the position using mobile networks.

Thank you!


回答1:


The main permissions you need are android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.

Only fine location will allow you access to gps data, and allows you access to everything else coarse location gives. You can use the methods of the LocationManager to acquire location data from gps and cell tower sources already, you do not have to work out this information yourself.

If you are targeting API Level 21 (5.0) or higher, you may also need this:

<uses-feature android:name="android.hardware.location.gps" />



回答2:


This permission should allow your app to use location services through the devices GPS, wifi, and cell towers. Just plop it in your manifest wherever you put your permissions, and it should do the trick. You can find all the other permissions here: (http://developer.android.com/reference/android/Manifest.permission.html)

Here is the code:

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



回答3:


I had the same issue and noticed that the code was requesting high accuracy but the manifest had course permissions. I changed it to fine and the error no longer occurs.

Make sure the code and the manifest reflect the same level of accuracy requested and allowed.

So if the manifest has android.permission.ACCESS_FINE_LOCATION the application can request geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high...



来源:https://stackoverflow.com/questions/21358392/android-location-permissions

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