-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method for permission state. #944
Comments
Hi @infacto, agree this would be a useful feature to have. It's not currently possible to check the permissions using this plugin on it's own. In my current applications I've been using the cordova-diagnostic-plugin to support this workflow, but it's certainly a pain having to keep these permission checks aligned with the plugin as well, especially given the permissions are different for each Android release. |
Yep. This varies between phone manufacturers, making Android extra fun.
This is due to Android's behaviour when the permission dialog appears. The permission dialog effectively pauses the requesting app until the permission is granted/denied, at which point the app resumes.
On Android 12, this setting is called |
Ok thanks, I found the permission now. Another issue is: You can disable location at any time. For example pull down the Android control center and tap on location. Then call this ble plugin |
Though most phones do require location services enabled to scan, not every phone does. I haven't yet figured out a good solution to tell whether the scan works or not, as Android doesn't return any error, it just ignored the scan request silently. More discussion in this can be found here: #872 |
Just another idea / think aloud: If possible we could implement a method to open permission setting (where is e.g. "nearby devices") for this app. Like the method cordova.plugins.diagnostic.getPermissionAuthorizationStatus(
(status) => console.log('Status:', status),
(error) => console.error('Error:', error),
'BLUETOOTH_SCAN'
)
// Result in case the permission was denied by the user and the dialog is never shown again:
// Status: DENIED_ALWAYS (btw. NOT_REQUESTED is also possible. Read more in docs.) Btw. it seems that there are two DENIED state. ONCE and TWICE. So it's intended from Android. When the user denied twice, the dialog does not appear anymore. But idk. if different devices acts in different way. ... Update: I think getBluetoothAuthorizationStatuses is the better choice. Or just getBluetoothAuthorizationStatus |
Should we add a method for the new Android 12+ permissions?
isEnabled
isLocationEnabled
isScanEnabled
new
How to test permission
BLUETOOTH_SCAN
? How to test if the bluetooth plugin is fully ready?Is it possible to test the permission before using it?
My test: On Android 12 you only get the permission dialog two times. When you get the error "Bluetooth scan permission not granted." Btw. before this error the app event
platform.pause
is emitted and after this errorplatform.resume
. That's weird. Another thing is, I have no idea where to enable BLUETOOTH_SCAN in Android settings. I cannot find it. Currently I have to uninstall the app and install again to trigger the permission dialog. We need a way to trigger this again or open settings if the user must manually enable it.Btw. Are all errors always typeof
string
? For example onstartScanWithOptions
? Because we generally expectError
object. I could test string if includesscan
andpermission
to handle this kind of error. ^^Ref. #875
The text was updated successfully, but these errors were encountered: