I am trying to request Bluetooth permissions required for the Bluetooth discovery process. I have have been able to successfully request permission from the user, but when I check for permission, before calling startDiscovery(), it returns false for BLUETOOTH_CONNECT, even if the permissions were given by the user. Like the title says, is there a way around this?
this is the my instantiation of an activity result launcher:
val permissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted: Boolean ->
if (granted) {
textView1.text = "permission granted"
} else {
textView1.text = "not granted"
}
}
This is my code where I launch the activity result launcher with the permissions I need( I wasn't sure how to request multiple permissions at once):
permissionLauncher.launch(Manifest.permission.BLUETOOTH_CONNECT)
permissionLauncher.launch(Manifest.permission.BLUETOOTH_SCAN)
I am trying to request Bluetooth permissions required for the Bluetooth discovery process. I have have been able to successfully request permission from the user, but when I check for permission, before calling startDiscovery(), it returns false for BLUETOOTH_CONNECT, even if the permissions were given by the user. Like the title says, is there a way around this?
this is the my instantiation of an activity result launcher:
val permissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted: Boolean ->
if (granted) {
textView1.text = "permission granted"
} else {
textView1.text = "not granted"
}
}
This is my code where I launch the activity result launcher with the permissions I need( I wasn't sure how to request multiple permissions at once):
permissionLauncher.launch(Manifest.permission.BLUETOOTH_CONNECT)
permissionLauncher.launch(Manifest.permission.BLUETOOTH_SCAN)
Share
Improve this question
edited Mar 19 at 7:11
tomerpacific
6,59818 gold badges41 silver badges60 bronze badges
asked Mar 18 at 21:54
Zero_CoolV2.0Zero_CoolV2.0
133 bronze badges
1
|
1 Answer
Reset to default 1You should use ActivityCompat.requestPermissions() with an array of permissions to request permissions, it is likely that only one of your permissions is being granted.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744490054a4576792.html
ActivityResultContracts.RequestMultiplePermissions
and see if that helps. See the docs. – CommonsWare Commented Mar 18 at 21:59