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" />
requestPermissions
? android.permission.ACCESS_FINE_LOCATION
but not the others, why?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-.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With