admin管理员组文章数量:1386490
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.
版权声明:本文标题:android bluetooth - App permissions for BLUETOOTH_CONNECT returns false until app is restarted - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744490054a2608680.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
ActivityResultContracts.RequestMultiplePermissions
and see if that helps. See the docs. – CommonsWare Commented Mar 18 at 21:59