diff --git a/src/android/BLECentralPlugin.java b/src/android/BLECentralPlugin.java index 1514a96d..038d15f2 100644 --- a/src/android/BLECentralPlugin.java +++ b/src/android/BLECentralPlugin.java @@ -53,6 +53,8 @@ import java.util.*; +import androidx.core.content.ContextCompat; + import static android.bluetooth.BluetoothDevice.DEVICE_TYPE_DUAL; import static android.bluetooth.BluetoothDevice.DEVICE_TYPE_LE; import static android.bluetooth.BluetoothDevice.ACTION_BOND_STATE_CHANGED; @@ -114,6 +116,8 @@ public class BLECentralPlugin extends CordovaPlugin { private static final String START_LOCATION_STATE_NOTIFICATIONS = "startLocationStateNotifications"; private static final String STOP_LOCATION_STATE_NOTIFICATIONS = "stopLocationStateNotifications"; + private static final int RECEIVER_EXPORTED = 0x2; // ContextCompat.RECEIVER_EXPORTED + // callbacks CallbackContext discoverCallback; private CallbackContext enableBluetoothCallback; @@ -660,7 +664,7 @@ public void onReceive(Context context, Intent intent) { try { IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); - webView.getContext().registerReceiver(this.stateReceiver, intentFilter); + ContextCompat.registerReceiver(webView.getContext(), stateReceiver, intentFilter, RECEIVER_EXPORTED); } catch (Exception e) { LOG.e(TAG, "Error registering state receiver: " + e.getMessage(), e); } @@ -707,7 +711,7 @@ public void onReceive(Context context, Intent intent) { try { IntentFilter intentFilter = new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION); intentFilter.addAction(Intent.ACTION_PROVIDER_CHANGED); - webView.getContext().registerReceiver(this.locationStateReceiver, intentFilter); + ContextCompat.registerReceiver(webView.getContext(), this.locationStateReceiver, intentFilter, RECEIVER_EXPORTED); } catch (Exception e) { LOG.e(TAG, "Error registering location state receiver: " + e.getMessage(), e); } @@ -742,7 +746,7 @@ private void connect(CallbackContext callbackContext, String macAddress) { return; } - if (!peripherals.containsKey(macAddress) && BLECentralPlugin.this.bluetoothAdapter.checkBluetoothAddress(macAddress)) { + if (!peripherals.containsKey(macAddress) && BluetoothAdapter.checkBluetoothAddress(macAddress)) { BluetoothDevice device = BLECentralPlugin.this.bluetoothAdapter.getRemoteDevice(macAddress); Peripheral peripheral = new Peripheral(device); peripherals.put(macAddress, peripheral); @@ -848,7 +852,7 @@ public void onReceive(Context context, Intent intent) { IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); - webView.getContext().registerReceiver(broadCastReceiver, intentFilter); + ContextCompat.registerReceiver(webView.getContext(), broadCastReceiver, intentFilter, RECEIVER_EXPORTED); callbackContext.success("OK"); } catch (Exception e) { @@ -1506,7 +1510,7 @@ public void onReceive(Context context, Intent intent) { } } }; - ContextCompat.registerReceiver(webView.getContext(), bondStateReceiver, new IntentFilter(ACTION_BOND_STATE_CHANGED), ContextCompat.RECEIVER_EXPORTED); + ContextCompat.registerReceiver(webView.getContext(), bondStateReceiver, new IntentFilter(ACTION_BOND_STATE_CHANGED), RECEIVER_EXPORTED); } }