Created
April 9, 2020 17:46
-
-
Save aya-salama1989/fba7459916c7ca917ed629f200eabdf3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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