Skip to content

Instantly share code, notes, and snippets.

@aya-salama1989
Created April 9, 2020 17:46
Show Gist options
  • Save aya-salama1989/fba7459916c7ca917ed629f200eabdf3 to your computer and use it in GitHub Desktop.
Save aya-salama1989/fba7459916c7ca917ed629f200eabdf3 to your computer and use it in GitHub Desktop.
private fun allowLocationDetectionPermissions() {
if (ContextCompat.checkSelfPermission(this@MainActivity, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_DENIED) {
ActivityCompat.requestPermissions(this@MainActivity,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), FINE_LOCATION_PERMISSION_REQUEST)
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
when (requestCode) {
FINE_LOCATION_PERMISSION_REQUEST -> {
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
scanLeDevice(true)
} else {
//notify the user to allow location detection otherwise the scaning won't work
}
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment