@capacitor-community/bluetooth-le 3.1.0 → 3.1.2
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/README.md
CHANGED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
</p>
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
|
-
<img src="https://img.shields.io/maintenance/yes/
|
|
9
|
+
<img src="https://img.shields.io/maintenance/yes/2024?style=flat-square" />
|
|
10
10
|
<a href="https://github.com/capacitor-community/bluetooth-le/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/actions/workflow/status/capacitor-community/bluetooth-le/main.yml?branch=main&style=flat-square" /></a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/@capacitor-community/bluetooth-le"><img src="https://img.shields.io/npm/l/@capacitor-community/bluetooth-le?style=flat-square" /></a>
|
|
12
12
|
<br>
|
|
13
13
|
<a href="https://www.npmjs.com/package/@capacitor-community/bluetooth-le"><img src="https://img.shields.io/npm/dw/@capacitor-community/bluetooth-le?style=flat-square" /></a>
|
|
14
14
|
<a href="https://www.npmjs.com/package/@capacitor-community/bluetooth-le"><img src="https://img.shields.io/npm/v/@capacitor-community/bluetooth-le?style=flat-square" /></a>
|
|
15
15
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
16
|
-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-
|
|
16
|
+
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-16-orange?style=flat-square" /></a>
|
|
17
17
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
18
|
</p>
|
|
19
19
|
|
|
@@ -38,7 +38,9 @@ This is a Capacitor plugin for Bluetooth Low Energy. It supports the web, Androi
|
|
|
38
38
|
|
|
39
39
|
The goal is to support the same features on all platforms. Therefore the [Web Bluetooth API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API) is taken as a guidline for what features to implement.
|
|
40
40
|
|
|
41
|
-
This plugin only supports
|
|
41
|
+
This plugin only supports Bluetooth **Low Energy**, not Bluetooth serial / classic.
|
|
42
|
+
|
|
43
|
+
Furthermore the plugin only supports the central role of the Bluetooth Low Energy protocol. If you need the peripheral role, take a look a these plugins:
|
|
42
44
|
|
|
43
45
|
- https://github.com/randdusing/cordova-plugin-bluetoothle
|
|
44
46
|
- https://github.com/don/cordova-plugin-ble-peripheral
|
|
@@ -127,7 +129,7 @@ If the app needs to use Bluetooth while it is in the background, you also have t
|
|
|
127
129
|
|
|
128
130
|
### Android
|
|
129
131
|
|
|
130
|
-
On Android, no further steps are required to use the plugin
|
|
132
|
+
On Android, no further steps are required to use the plugin.
|
|
131
133
|
|
|
132
134
|
#### (Optional) Android 12 Bluetooth permissions
|
|
133
135
|
|
|
@@ -136,8 +138,6 @@ If your app targets Android 12 (API level 31) or higher and your app doesn't use
|
|
|
136
138
|
The following steps are required to scan for Bluetooth devices without location permission on Android 12 devices:
|
|
137
139
|
|
|
138
140
|
- In `android/variables.gradle`, make sure `compileSdkVersion` and `targetSdkVersion` are at least 31 (changing those values can have other consequences on your app, so make sure you know what you're doing).
|
|
139
|
-
- Make sure you have JDK 11+ (it is recommended to use JDK that comes with Android Studio).
|
|
140
|
-
- In `android/app/src/main/AndroidManifest.xml`, add `android:exported="true"` to your activity if not already added (setting [`android:exported`](https://developer.android.com/guide/topics/manifest/activity-element#exported) is required in apps targeting Android 12 and higher).
|
|
141
141
|
- In `android/app/src/main/AndroidManifest.xml`, update the permissions:
|
|
142
142
|
```diff
|
|
143
143
|
<!-- Permissions -->
|
|
@@ -198,16 +198,15 @@ The display strings can also be set at run-time using [`setDisplayStrings(...)`]
|
|
|
198
198
|
|
|
199
199
|
## Usage
|
|
200
200
|
|
|
201
|
-
|
|
201
|
+
There is a plugin wrapper class `BleClient` which makes events and method arguments easier to work with.
|
|
202
202
|
|
|
203
203
|
```typescript
|
|
204
|
-
// Import the wrapper class
|
|
204
|
+
// Import the wrapper class
|
|
205
205
|
import { BleClient } from '@capacitor-community/bluetooth-le';
|
|
206
|
-
|
|
207
|
-
// DO NOT use this
|
|
208
|
-
import { BluetoothLe } from '@capacitor-community/bluetooth-le';
|
|
209
206
|
```
|
|
210
207
|
|
|
208
|
+
**Note**: It is not recommended to use the `BluetoothLe` plugin class directly.
|
|
209
|
+
|
|
211
210
|
### Heart rate monitor
|
|
212
211
|
|
|
213
212
|
Here is an example of how to use the plugin. It shows how to read the heart rate from a BLE heart rate monitor such as the Polar H10.
|
|
@@ -354,8 +353,8 @@ _Note_: web support depends on the browser, see [implementation status](https://
|
|
|
354
353
|
| [`readRssi(...)`](#readrssi) | ✅ | ✅ | ❌ |
|
|
355
354
|
| [`read(...)`](#read) | ✅ | ✅ | ✅ |
|
|
356
355
|
| [`write(...)`](#write) | ✅ | ✅ | ✅ |
|
|
357
|
-
| [`readDescriptor(...)`](#
|
|
358
|
-
| [`writeDescriptor(...)`](#
|
|
356
|
+
| [`readDescriptor(...)`](#readdescriptor) | ✅ | ✅ | ✅ |
|
|
357
|
+
| [`writeDescriptor(...)`](#writedescriptor) | ✅ | ✅ | ✅ |
|
|
359
358
|
| [`writeWithoutResponse(...)`](#writewithoutresponse) | ✅ | ✅ | ✅ |
|
|
360
359
|
| [`startNotifications(...)`](#startnotifications) | ✅ | ✅ | ✅ |
|
|
361
360
|
| [`stopNotifications(...)`](#stopnotifications) | ✅ | ✅ | ✅ |
|
|
@@ -1108,6 +1107,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
1108
1107
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/td-tomasz-joniec"><img src="https://avatars.githubusercontent.com/u/109506928?v=4?s=100" width="100px;" alt="td-tomasz-joniec"/><br /><sub><b>td-tomasz-joniec</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=td-tomasz-joniec" title="Code">💻</a></td>
|
|
1109
1108
|
<td align="center" valign="top" width="14.28%"><a href="https://fanxj.com"><img src="https://avatars.githubusercontent.com/u/10436013?v=4?s=100" width="100px;" alt="Michele Ferrari"/><br /><sub><b>Michele Ferrari</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=micheleypf" title="Code">💻</a></td>
|
|
1110
1109
|
</tr>
|
|
1110
|
+
<tr>
|
|
1111
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mchl18"><img src="https://avatars.githubusercontent.com/u/6136970?v=4?s=100" width="100px;" alt="mchl18"/><br /><sub><b>mchl18</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=mchl18" title="Documentation">📖</a></td>
|
|
1112
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/OpenSrcerer"><img src="https://avatars.githubusercontent.com/u/46500918?v=4?s=100" width="100px;" alt="Daniel Stefani"/><br /><sub><b>Daniel Stefani</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=OpenSrcerer" title="Code">💻</a></td>
|
|
1113
|
+
</tr>
|
|
1111
1114
|
</tbody>
|
|
1112
1115
|
</table>
|
|
1113
1116
|
|
package/android/build.gradle
CHANGED
|
@@ -2,6 +2,7 @@ package com.capacitorjs.community.plugins.bluetoothle
|
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
4
|
import android.annotation.SuppressLint
|
|
5
|
+
import android.app.Activity
|
|
5
6
|
import android.bluetooth.BluetoothAdapter
|
|
6
7
|
import android.bluetooth.BluetoothAdapter.ACTION_REQUEST_ENABLE
|
|
7
8
|
import android.bluetooth.BluetoothDevice
|
|
@@ -24,6 +25,7 @@ import android.os.ParcelUuid
|
|
|
24
25
|
import android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
|
25
26
|
import android.provider.Settings.ACTION_BLUETOOTH_SETTINGS
|
|
26
27
|
import android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
|
|
28
|
+
import androidx.activity.result.ActivityResult
|
|
27
29
|
import androidx.core.location.LocationManagerCompat
|
|
28
30
|
import com.getcapacitor.JSArray
|
|
29
31
|
import com.getcapacitor.JSObject
|
|
@@ -32,6 +34,7 @@ import com.getcapacitor.PermissionState
|
|
|
32
34
|
import com.getcapacitor.Plugin
|
|
33
35
|
import com.getcapacitor.PluginCall
|
|
34
36
|
import com.getcapacitor.PluginMethod
|
|
37
|
+
import com.getcapacitor.annotation.ActivityCallback
|
|
35
38
|
import com.getcapacitor.annotation.CapacitorPlugin
|
|
36
39
|
import com.getcapacitor.annotation.Permission
|
|
37
40
|
import com.getcapacitor.annotation.PermissionCallback
|
|
@@ -164,9 +167,18 @@ class BluetoothLe : Plugin() {
|
|
|
164
167
|
|
|
165
168
|
@PluginMethod
|
|
166
169
|
fun requestEnable(call: PluginCall) {
|
|
170
|
+
assertBluetoothAdapter(call) ?: return
|
|
167
171
|
val intent = Intent(ACTION_REQUEST_ENABLE)
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
startActivityForResult(call, intent, "handleRequestEnableResult")
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@ActivityCallback
|
|
176
|
+
private fun handleRequestEnableResult(call: PluginCall, result: ActivityResult) {
|
|
177
|
+
if (result.resultCode == Activity.RESULT_OK) {
|
|
178
|
+
call.resolve()
|
|
179
|
+
} else {
|
|
180
|
+
call.reject("requestEnable failed.")
|
|
181
|
+
}
|
|
170
182
|
}
|
|
171
183
|
|
|
172
184
|
@PluginMethod
|