Created
May 1, 2020 23:57
-
-
Save wajahatkarim3/779bf59867696f5574e7e331ca3ed8b8 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
// Requesting Location Permission | |
bi.btnRequestPermission.setOnClickListener { | |
askLocationPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) | |
} | |
// Single Permission Contract | |
private val askLocationPermission = registerForActivityResult(ActivityResultContracts.RequestPermission()) { result -> | |
if(result){ | |
Log.e("TAG", "Location permnission granted") | |
}else{ | |
Log.e("TAG", "Location permnission denied") | |
} | |
} | |
// ------------------------------------------------------------------- | |
// Requesting Mutliple Permissions - Location & Bluetooth | |
bi.btnRequestPermission.setOnClickListener { | |
askMultiplePermissions(arrayOf( | |
android.Manifest.permission.ACCESS_FINE_LOCATION, | |
android.Manifest.permission.BLUETOOTH | |
)) | |
} | |
// Mutliple Permissions Contract | |
private val askMultiplePermissions = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {map -> | |
for (entry in map.entries) | |
{ | |
Toast.makeText(this, "${entry.key} = ${entry.value}", Toast.LENGTH_SHORT).show() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment