@capacitor-community/bluetooth-le 3.1.0 → 3.1.1

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
@@ -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 the central role of the Bluetooth Low Energy protocol. If you need the peripheral role, take a look a these plugins:
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 (if you are using Capacitor 2, see [here](https://github.com/capacitor-community/bluetooth-le/blob/0.x/README.md#android)).
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
- It is recommended to not use the plugin class directly. There is a wrapper class `BleClient` which makes events and method arguments easier to work with.
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 directly
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.
@@ -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
- activity.startActivity(intent)
169
- call.resolve()
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/bluetooth-le",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Capacitor plugin for Bluetooth Low Energy ",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",