Marshmallow FINE and COARSE location permission

佐手、 提交于 2019-12-04 16:11:05

问题


I'm trying to access ACCESS_FINE_LOCATION and if it cannot be found access ACCESS_COARSE_LOCATION. So I request for those 2 permission, but they give me the same dialog asking for location permission. I know those are both in the same group but Google says:

Note: Your app still needs to explicitly request every permission it needs, even if the user has already granted another permission in the same group. In addition, the grouping of permissions into groups may change in future Android releases. Your code should not rely on the assumption that particular permissions are or are not in the same group.

This means I ask for those 2 permissions within a second, which results in 2 dialog in a row. THis does not seem very user friendly to me. Is there a better way?


回答1:


You do not need ACCESS_COARSE_LOCATION permission when you define ACCESS_FINE_LOCATION permission.

From Android Documentation:

Requesting User Permissions

In order to receive location updates from NETWORK_PROVIDER or GPS_PROVIDER, you must request user permission by declaring either the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, respectively, in your Android manifest file. For example:

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

Without these permissions, your application will fail at runtime when requesting location updates.

Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)

Please look at https://developer.android.com/guide/topics/location/strategies.html




回答2:


I have resolved the same problem.Try to give it runtime permission and Firstly check the manifest SDK version and if your version is greater than 6.0 or equal to 6.0 then you need to check permissions for your permission and pass permission Fine location only in request location then definitely it will work.

if you got stuck in code then you may ask for code I will update you but firstly go through these steps. if you got success to perform your task then rate it.



来源:https://stackoverflow.com/questions/33780331/marshmallow-fine-and-coarse-location-permission

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