react-native-ble-manager 11.5.1 → 11.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/it/innove/BleManager.java +9 -5
- package/android/src/main/java/it/innove/CompanionScanner.java +5 -0
- package/android/src/main/java/it/innove/DefaultScanManager.java +6 -0
- package/android/src/main/java/it/innove/LegacyScanManager.java +5 -0
- package/android/src/main/java/it/innove/ScanManager.java +2 -0
- package/package.json +1 -1
|
@@ -2,8 +2,6 @@ package it.innove;
|
|
|
2
2
|
|
|
3
3
|
import static android.app.Activity.RESULT_OK;
|
|
4
4
|
import static android.bluetooth.BluetoothProfile.GATT;
|
|
5
|
-
import static android.os.Build.VERSION_CODES.LOLLIPOP;
|
|
6
|
-
import static android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE;
|
|
7
5
|
import android.annotation.SuppressLint;
|
|
8
6
|
import android.app.Activity;
|
|
9
7
|
import android.bluetooth.BluetoothAdapter;
|
|
@@ -167,11 +165,11 @@ class BleManager extends ReactContextBaseJavaModule {
|
|
|
167
165
|
filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
|
|
168
166
|
IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
|
|
169
167
|
intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
|
170
|
-
if (Build.VERSION.SDK_INT >=
|
|
168
|
+
if (Build.VERSION.SDK_INT >= 34){
|
|
171
169
|
// Google in 2023 decides that flag RECEIVER_NOT_EXPORTED or RECEIVER_EXPORTED should be explicit set SDK 34(UPSIDE_DOWN_CAKE) on registering receivers.
|
|
172
170
|
// Also the export flags are available on Android 8 and higher, should be used with caution so that don't break compability with that devices.
|
|
173
|
-
context.registerReceiver(mReceiver, filter, Context.
|
|
174
|
-
context.registerReceiver(mReceiver, intentFilter, Context.
|
|
171
|
+
context.registerReceiver(mReceiver, filter, Context.RECEIVER_EXPORTED);
|
|
172
|
+
context.registerReceiver(mReceiver, intentFilter, Context.RECEIVER_EXPORTED);
|
|
175
173
|
} else {
|
|
176
174
|
context.registerReceiver(mReceiver, filter);
|
|
177
175
|
context.registerReceiver(mReceiver, intentFilter);
|
|
@@ -565,11 +563,17 @@ class BleManager extends ReactContextBaseJavaModule {
|
|
|
565
563
|
break;
|
|
566
564
|
case BluetoothAdapter.STATE_TURNING_OFF:
|
|
567
565
|
state = "turning_off";
|
|
566
|
+
if (scanManager != null) {
|
|
567
|
+
scanManager.setScanning(false);
|
|
568
|
+
}
|
|
568
569
|
break;
|
|
569
570
|
case BluetoothAdapter.STATE_OFF:
|
|
570
571
|
default:
|
|
571
572
|
// should not happen as per https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getState()
|
|
572
573
|
state = "off";
|
|
574
|
+
if (scanManager != null) {
|
|
575
|
+
scanManager.setScanning(false);
|
|
576
|
+
}
|
|
573
577
|
break;
|
|
574
578
|
}
|
|
575
579
|
}
|
|
@@ -64,10 +64,12 @@ public class CompanionScanner {
|
|
|
64
64
|
if (peripheral != null && scanCallback != null) {
|
|
65
65
|
scanCallback.invoke(null, peripheral.asWritableMap());
|
|
66
66
|
scanCallback = null;
|
|
67
|
+
bleManager.sendEvent("BleManagerCompanionPeripheral", peripheral.asWritableMap());
|
|
67
68
|
}
|
|
68
69
|
} else {
|
|
69
70
|
scanCallback.invoke(null, null);
|
|
70
71
|
scanCallback = null;
|
|
72
|
+
bleManager.sendEvent("BleManagerCompanionPeripheral", null);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
} else {
|
|
@@ -122,6 +124,9 @@ public class CompanionScanner {
|
|
|
122
124
|
Log.d(LOG_TAG, "companion failure: " + charSequence);
|
|
123
125
|
scanCallback.invoke("Companion association failed: " + charSequence.toString());
|
|
124
126
|
scanCallback = null;
|
|
127
|
+
WritableMap map = Arguments.createMap();
|
|
128
|
+
map.putString("error", charSequence.toString());
|
|
129
|
+
bleManager.sendEvent("BleManagerCompanionFailure", map);
|
|
125
130
|
}
|
|
126
131
|
|
|
127
132
|
@Override
|
|
@@ -255,7 +255,13 @@ public class DefaultScanManager extends ScanManager {
|
|
|
255
255
|
}
|
|
256
256
|
};
|
|
257
257
|
|
|
258
|
+
@Override
|
|
258
259
|
public boolean isScanning() {
|
|
259
260
|
return isScanning;
|
|
260
261
|
}
|
|
262
|
+
|
|
263
|
+
@Override
|
|
264
|
+
public void setScanning(boolean scanning) {
|
|
265
|
+
isScanning = scanning;
|
|
266
|
+
}
|
|
261
267
|
}
|