Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MarshMallow Permission for gmaps

If gmaps needs this permissions:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  1. should I ask for each one to the user with requestPermissions ?
  2. I checked some times and it only crash saying that the user didnt give permissions for android.permission.ACCESS_FINE_LOCATIONbut not the others, why?
like image 233
Daniel Gomez Rico Avatar asked Sep 23 '15 14:09

Daniel Gomez Rico


2 Answers

should I ask for each one to the user with requestPermissions ?

First when to use requestPermission ?

requestPermission is only call after checkSelfPermission when this method doesn't return PERMISSION_GRANTED.

You can find a list of permission that android M requires during the runtime. Each of these Permissions are part of a Permission group. WRITE_EXTERNAL_PERMISSION is from android.permission-group.STORAGE and ACCESS_COARSE_LOCATION / ACCESS_FINE_LOCATION are from android.permission-group.LOCATION.

If the user allows the access to a permission -for example ACCESS_COARSE_LOCATION-, then android will automatically grant the access of this permission group -i.e. permission-group.LOCATION-. So if you later checkSelfPermission for ACCESS_FINE_LOCATION, you should receive PackageManager.PERMISSION_GRANTED.

If you app crashes, it means that you tried to call, for example LocationServices.FusedLocationApi.requestLocationUpdates before requesting from the user the permission-group Location.

Edit:

Do not forget that requestPermission is asynchronous. So do not call a method that requires a permission right after requestPermission. To call a method that requires a permission, you should override onRequestPermissionsResult that give you a list of permission and their state -granted/denied-.

like image 72
xiaomi Avatar answered Nov 02 '22 11:11

xiaomi


You should only need to request permission for the LOCATION and STORAGE groups. I'm also pretty sure Fine location includes permission for Coarse, so you don't need to include that line in your manifest.

like image 44
Paul Ruiz Avatar answered Nov 02 '22 11:11

Paul Ruiz