Basic permission snippet for Google Maps
A simple kotlin snippet to insert if you want to trigger the Android location permission dialog in mobile. The "Toast" part is optional.
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
val text = "No permissions detected!"
val duration = Toast.LENGTH_SHORT
val toast = Toast.makeText(applicationContext, text, duration)
toast.show()
ActivityCompat.requestPermissions(
this,
arrayOf<String>(Manifest.permission.ACCESS_FINE_LOCATION),
REQUEST_LOCATION_PERMISSION
)
return
}
Remember to place this snippet immediately before the code/feature that requires permissions. For example:
mMap.isMyLocationEnabled = true
→