@@ -20,37 +20,37 @@ having this be a default. As of AGP 3.2 there is no reason not to do this
20
20
21
21
1 . Replace ` initGatt(BluetoothGatt) ` with ` initialize() ` :
22
22
23
- Old code:
24
- ``` java
25
- @Override
26
- protected Deque<Request > initGatt(final BluetoothGatt gatt) {
27
- final LinkedList<Request > requests = new LinkedList<> ();
28
- requests. add(Request . newEnableNotificationsRequest(characteristic));
29
- return requests;
30
- }
31
- ```
32
- New code:
33
- ``` java
34
- @Override
35
- protected void initialize() {
36
- setNotificationCallback(characteristic)
37
- .with(new DataReceivedCallback () {
38
- @Override
39
- public void onDataReceived (@NonNull final BluetoothDevice device , @NonNull final Data data ) {
40
- ...
41
- }
42
- });
43
- enableNotifications(characteristic)
44
- .enqueue();
45
- }
46
- ```
47
-
48
- See changes in [ Android nRF Toolbox] ( https://github.com/NordicSemiconductor/Android-nRF-Toolbox/ )
49
- and [ Android nRF Blinky] ( https://github.com/NordicSemiconductor/Android-nRF-Blinky/ ) for more examples.
50
-
51
- Remember to call ` .enqueue() ` method for initialization requests!
52
-
53
- Connect 's completion callback is called after the initialization is done (without or with errors).
23
+ Old code:
24
+ ``` java
25
+ @Override
26
+ protected Deque<Request > initGatt(final BluetoothGatt gatt) {
27
+ final LinkedList<Request > requests = new LinkedList<> ();
28
+ requests. add(Request . newEnableNotificationsRequest(characteristic));
29
+ return requests;
30
+ }
31
+ ```
32
+ New code:
33
+ ``` java
34
+ @Override
35
+ protected void initialize() {
36
+ setNotificationCallback(characteristic)
37
+ .with(new DataReceivedCallback () {
38
+ @Override
39
+ public void onDataReceived (@NonNull final BluetoothDevice device , @NonNull final Data data ) {
40
+ ...
41
+ }
42
+ });
43
+ enableNotifications(characteristic)
44
+ .enqueue();
45
+ }
46
+ ```
47
+
48
+ See changes in [ Android nRF Toolbox] ( https://github.com/NordicSemiconductor/Android-nRF-Toolbox/ )
49
+ and [ Android nRF Blinky] ( https://github.com/NordicSemiconductor/Android-nRF-Blinky/ ) for more examples.
50
+
51
+ Remember to call ` .enqueue() ` method for initialization requests!
52
+
53
+ ` ConnectRequest ` 's completion callback is called after the initialization is done (without or with errors).
54
54
55
55
2 . Move your callback implementation from ` BleManagerGattCallback ` to request callbacks.
56
56
3 . To split logic from parsing, we recommend to extend ` DataReceivedCallback ` interface in a class
@@ -84,34 +84,34 @@ It has all the parsers implemented. If your profile isn't there, we are happy to
84
84
85
85
1 . To make quick transition from 2.1 to 2.2, change the base class of your ` BleManager ` implementation
86
86
to ` LegacyBleManager ` and make sure you return an object (not * null* ) from ` getGattCallback() ` :
87
+
88
+ ``` java
89
+ class MyBleManager extends LegacyBleManager<MyBleManagerCallbacks > {
87
90
88
- ``` java
89
- class MyBleManager extends LegacyBleManager<MyBleManagerCallbacks > {
90
-
91
- // [...]
92
-
93
- @NonNull
94
- @Override
95
- protected BleManagerGattCallback getGattCallback () {
96
- // Before 2.2 it was allowed to return a class property here, but properties are initiated
97
- // after the constructor, so they would still be null here. Instead, create a new object:
98
- return new MyBleManagerGattCallback ();
99
- }
100
-
101
- // [...]
102
-
103
- }
104
- ```
91
+ // [...]
92
+
93
+ @NonNull
94
+ @Override
95
+ protected BleManagerGattCallback getGattCallback () {
96
+ // Before 2.2 it was allowed to return a class property here, but properties are initiated
97
+ // after the constructor, so they would still be null here. Instead, create a new object:
98
+ return new MyBleManagerGattCallback ();
99
+ }
100
+
101
+ // [...]
102
+
103
+ }
104
+ ```
105
105
106
106
#### Proper migration
107
107
108
108
1 . Remove the type parameter from your ` BleManager ` implementation class:
109
109
110
- ``` java
111
- class MyBleManager extends BleManager {
112
- // [...]
113
- }
114
- ```
110
+ ``` java
111
+ class MyBleManager extends BleManager {
112
+ // [...]
113
+ }
114
+ ```
115
115
116
116
2 . Replace ` setGattCallbacks(callbacks) ` with ` setConnectionObserver(observer) ` and optionally
117
117
` setBondingObserver(observer) ` . If you are using ` androidx.lifecycle.LiveData ` , consider using
@@ -132,4 +132,9 @@ class MyBleManager extends BleManager {
132
132
which could have been used to notify a Service or Activity about incoming notifications, etc.
133
133
As ` BleManager ` is no longer a generic type, you'll have to implement this logic on your own.
134
134
E.g., nRF Blinky is exposing LED and Button state using ` LiveData ` , which are available for the
135
- Activity through ` ViewModel ` .
135
+ Activity through ` ViewModel ` .
136
+
137
+ ## Changes in version 2.7
138
+
139
+ 1 . The Android BLE Library 2.7 was migrated to Java 17 due to minimum Java version in current
140
+ version of Android Studio.
0 commit comments