Skip to content
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

fix: android 12 enable permissions call #941

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/android/BLECentralPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,19 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback
} else if (action.equals(ENABLE)) {

enableBluetoothCallback = callbackContext;
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
cordova.startActivityForResult(this, intent, REQUEST_ENABLE_BLUETOOTH);

//check android12+ - perms should be asked in a bulk
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
String[] ANDROID_12_BLE_PERMISSIONS = new String[]{
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_CONNECT
};
cordova.requestPermissions(this, REQUEST_ENABLE_BLUETOOTH, ANDROID_12_BLE_PERMISSIONS);
}
else{
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
cordova.startActivityForResult(this, intent, REQUEST_ENABLE_BLUETOOTH);
}

} else if (action.equals(START_STATE_NOTIFICATIONS)) {

Expand Down Expand Up @@ -1227,6 +1238,12 @@ public void onRequestPermissionResult(int requestCode, String[] permissions, int
}

switch(requestCode) {
case REQUEST_ENABLE_BLUETOOTH:
LOG.d(TAG, "User enabled Bluetooth");
if (enableBluetoothCallback != null) {
enableBluetoothCallback.success();
}
break;
case REQUEST_BLUETOOTH_SCAN:
LOG.d(TAG, "User granted Bluetooth Scan Access");
findLowEnergyDevices(permissionCallback, serviceUUIDs, scanSeconds, scanSettings);
Expand Down