diff --git a/plugin.xml b/plugin.xml index 19558bbf..8b5d9515 100644 --- a/plugin.xml +++ b/plugin.xml @@ -33,6 +33,7 @@ + diff --git a/src/android/com/megster/cordova/BluetoothSerial.java b/src/android/com/megster/cordova/BluetoothSerial.java index 8be5575f..d698c5ae 100644 --- a/src/android/com/megster/cordova/BluetoothSerial.java +++ b/src/android/com/megster/cordova/BluetoothSerial.java @@ -86,6 +86,7 @@ public class BluetoothSerial extends CordovaPlugin { // Android 23 requires user to explicitly grant permission for location to discover unpaired private static final String ACCESS_COARSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION; + private static final String ACCESS_FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION; private static final int CHECK_PERMISSIONS_REQ_CODE = 2; private CallbackContext permissionCallback; @@ -213,11 +214,20 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback } else if (action.equals(DISCOVER_UNPAIRED)) { - if (cordova.hasPermission(ACCESS_COARSE_LOCATION)) { - discoverUnpairedDevices(callbackContext); - } else { - permissionCallback = callbackContext; - cordova.requestPermission(this, CHECK_PERMISSIONS_REQ_CODE, ACCESS_COARSE_LOCATION); + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { + if (cordova.hasPermission(ACCESS_FINE_LOCATION)) { + discoverUnpairedDevices(callbackContext); + } else { + permissionCallback = callbackContext; + cordova.requestPermission(this, CHECK_PERMISSIONS_REQ_CODE, ACCESS_FINE_LOCATION); + } + }else{ + if (cordova.hasPermission(ACCESS_COARSE_LOCATION)) { + discoverUnpairedDevices(callbackContext); + } else { + permissionCallback = callbackContext; + cordova.requestPermission(this, CHECK_PERMISSIONS_REQ_CODE, ACCESS_COARSE_LOCATION); + } } } else if (action.equals(SET_DEVICE_DISCOVERED_LISTENER)) {