Skip to content

Commit a67593c

Browse files
committed
Readme update
1 parent df5f70d commit a67593c

File tree

3 files changed

+116
-97
lines changed

3 files changed

+116
-97
lines changed

Diff for: MIGRATION.md

+59-54
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,37 @@ having this be a default. As of AGP 3.2 there is no reason not to do this
2020

2121
1. Replace `initGatt(BluetoothGatt)` with `initialize()`:
2222

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).
5454

5555
2. Move your callback implementation from `BleManagerGattCallback` to request callbacks.
5656
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
8484

8585
1. To make quick transition from 2.1 to 2.2, change the base class of your `BleManager` implementation
8686
to `LegacyBleManager` and make sure you return an object (not *null*) from `getGattCallback()`:
87+
88+
```java
89+
class MyBleManager extends LegacyBleManager<MyBleManagerCallbacks> {
8790

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+
```
105105

106106
#### Proper migration
107107

108108
1. Remove the type parameter from your `BleManager` implementation class:
109109

110-
```java
111-
class MyBleManager extends BleManager {
112-
// [...]
113-
}
114-
```
110+
```java
111+
class MyBleManager extends BleManager {
112+
// [...]
113+
}
114+
```
115115

116116
2. Replace `setGattCallbacks(callbacks)` with `setConnectionObserver(observer)` and optionally
117117
`setBondingObserver(observer)`. If you are using `androidx.lifecycle.LiveData`, consider using
@@ -132,4 +132,9 @@ class MyBleManager extends BleManager {
132132
which could have been used to notify a Service or Activity about incoming notifications, etc.
133133
As `BleManager` is no longer a generic type, you'll have to implement this logic on your own.
134134
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.

Diff for: README.md

+25-18
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@ notify about connection and bond state using `androidx.lifecycle.LiveData`.
3838
Clone this project and add it to your project:
3939

4040
1. In *settings.gradle* file add the following lines:
41-
```groovy
42-
if (file('../Android-BLE-Library').exists()) {
43-
includeBuild('../Android-BLE-Library')
44-
}
45-
```
41+
```groovy
42+
if (file('../Android-BLE-Library').exists()) {
43+
includeBuild('../Android-BLE-Library')
44+
}
45+
```
4646
2. Sync project and build it.
4747
48-
The library uses Java 1.8 features. If you're using Android Studio below 4.2, make sure your
49-
*build.gradle* includes the following configuration:
50-
51-
```groovy
52-
compileOptions {
53-
sourceCompatibility JavaVersion.VERSION_1_8
54-
targetCompatibility JavaVersion.VERSION_1_8
55-
}
56-
// For Kotlin projects additionally:
57-
kotlinOptions {
58-
jvmTarget = "1.8"
59-
}
60-
```
48+
The library uses Java 1.8 features. If you're using Android Studio below 4.2, make sure your
49+
*build.gradle* includes the following configuration:
50+
51+
```groovy
52+
compileOptions {
53+
sourceCompatibility JavaVersion.VERSION_1_8
54+
targetCompatibility JavaVersion.VERSION_1_8
55+
}
56+
// For Kotlin projects additionally:
57+
kotlinOptions {
58+
jvmTarget = "1.8"
59+
}
60+
```
6161
</details>
6262
6363
## Features
@@ -93,6 +93,13 @@ The library uses Java 1.8 features. If you're using Android Studio below 4.2, ma
9393
See [Releases](https://github.com/NordicSemiconductor/Android-BLE-Library/releases) for details.
9494
Below is short summary:
9595
96+
<details>
97+
<summary>Version 2.7</summary>
98+
99+
1. Library has been migrated to Java 17 due to minimum supported version in Android Studio Giraffe.
100+
101+
</details>
102+
96103
<details>
97104
<summary>Version 2.6</summary>
98105

Diff for: moustache/README.mo

+32-25
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@ notify about connection and bond state using `androidx.lifecycle.LiveData`.
3838
Clone this project and add it to your project:
3939

4040
1. In *settings.gradle* file add the following lines:
41-
```groovy
42-
if (file('../Android-BLE-Library').exists()) {
43-
includeBuild('../Android-BLE-Library')
44-
}
45-
```
41+
```groovy
42+
if (file('../Android-BLE-Library').exists()) {
43+
includeBuild('../Android-BLE-Library')
44+
}
45+
```
4646
2. Sync project and build it.
4747

48-
The library uses Java 1.8 features. If you're using Android Studio below 4.2, make sure your
49-
*build.gradle* includes the following configuration:
50-
51-
```groovy
52-
compileOptions {
53-
sourceCompatibility JavaVersion.VERSION_1_8
54-
targetCompatibility JavaVersion.VERSION_1_8
55-
}
56-
// For Kotlin projects additionally:
57-
kotlinOptions {
58-
jvmTarget = "1.8"
59-
}
60-
```
48+
The library uses Java 1.18 features. If you're using Android Studio below Giraffe, make sure your
49+
*build.gradle* includes the following configuration:
50+
51+
```groovy
52+
compileOptions {
53+
sourceCompatibility JavaVersion.VERSION_1_17
54+
targetCompatibility JavaVersion.VERSION_1_17
55+
}
56+
// For Kotlin projects additionally:
57+
kotlinOptions {
58+
jvmTarget = "1.17"
59+
}
60+
```
6161
</details>
6262

6363
## Features
@@ -93,6 +93,13 @@ The library uses Java 1.8 features. If you're using Android Studio below 4.2, ma
9393
See [Releases](https://github.com/NordicSemiconductor/Android-BLE-Library/releases) for details.
9494
Below is short summary:
9595

96+
<details>
97+
<summary>Version 2.7</summary>
98+
99+
1. Library has been migrated to Java 17 due to minimum supported version in Android Studio Giraffe.
100+
101+
</details>
102+
96103
<details>
97104
<summary>Version 2.6</summary>
98105

@@ -140,14 +147,14 @@ Below is short summary:
140147
4. Support for new `onServicesChanged()` callback, added in API 31 (Android 12).
141148
5. Option to cancel pending Bluetooth LE connection using `ConnectRequest.cancelPendingConnection()`.
142149

143-
When using coroutines, use `.suspend()` method in `Request`, instead of `enqueue()` or `await()`.
150+
When using coroutines, use `.suspend()` method in `Request`, instead of `enqueue()` or `await()`.
144151

145-
To register to notifications and indications (or incoming write requests for server) use
146-
```kotlin
147-
setNotificationCallback(characteristic)
148-
.merge(JsonMerger()) // Example of how to use JsonMerger, optional
149-
.asFlow()
150-
```
152+
To register to notifications and indications (or incoming write requests for server) use
153+
```kotlin
154+
setNotificationCallback(characteristic)
155+
.merge(JsonMerger()) // Example of how to use JsonMerger, optional
156+
.asFlow()
157+
```
151158
</details>
152159

153160
<details>

0 commit comments

Comments
 (0)