Refactor BLE plugin structure and rename to 'ble' for consistency across platforms
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
group 'com.dalimaster.ble_relay_host'
|
||||
group 'com.dalimaster.ble'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
buildscript {
|
||||
@@ -24,7 +24,7 @@ apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
namespace 'com.dalimaster.ble_relay_host'
|
||||
namespace 'com.dalimaster.ble'
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
|
||||
@@ -1 +1 @@
|
||||
include ':ble_relay_host'
|
||||
include ':ble'
|
||||
|
||||
+25
-8
@@ -1,6 +1,15 @@
|
||||
package com.dalimaster.ble_relay_host
|
||||
package com.dalimaster.ble
|
||||
|
||||
import android.bluetooth.*
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import android.bluetooth.BluetoothGatt
|
||||
import android.bluetooth.BluetoothGattCharacteristic
|
||||
import android.bluetooth.BluetoothGattDescriptor
|
||||
import android.bluetooth.BluetoothGattServer
|
||||
import android.bluetooth.BluetoothGattServerCallback
|
||||
import android.bluetooth.BluetoothGattService
|
||||
import android.bluetooth.BluetoothManager
|
||||
import android.bluetooth.BluetoothProfile
|
||||
import android.bluetooth.le.AdvertiseCallback
|
||||
import android.bluetooth.le.AdvertiseData
|
||||
import android.bluetooth.le.AdvertiseSettings
|
||||
@@ -16,11 +25,11 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
||||
import io.flutter.plugin.common.MethodChannel.Result
|
||||
import java.util.UUID
|
||||
|
||||
private const val TAG = "BleRelayHostPlugin"
|
||||
private const val CHANNEL = "com.dalimaster.ble_relay_host"
|
||||
private const val EVENT_CHANNEL = "com.dalimaster.ble_relay_host/clientWrites"
|
||||
private const val TAG = "BlePlugin"
|
||||
private const val CHANNEL = "com.dalimaster.ble"
|
||||
private const val EVENT_CHANNEL = "com.dalimaster.ble/clientWrites"
|
||||
|
||||
class BleRelayHostPlugin : FlutterPlugin, MethodCallHandler {
|
||||
class BlePlugin : FlutterPlugin, MethodCallHandler {
|
||||
|
||||
private lateinit var methodChannel: MethodChannel
|
||||
private lateinit var eventChannel: EventChannel
|
||||
@@ -53,6 +62,7 @@ class BleRelayHostPlugin : FlutterPlugin, MethodCallHandler {
|
||||
override fun onListen(arguments: Any?, sink: EventChannel.EventSink?) {
|
||||
eventSink = sink
|
||||
}
|
||||
|
||||
override fun onCancel(arguments: Any?) {
|
||||
eventSink = null
|
||||
}
|
||||
@@ -79,18 +89,24 @@ class BleRelayHostPlugin : FlutterPlugin, MethodCallHandler {
|
||||
?: "0000fff1-0000-1000-8000-00805f9b34fb"
|
||||
startInternal(advertisedName, serviceUuidStr, charUuidStr, result)
|
||||
}
|
||||
|
||||
"push" -> {
|
||||
val data = call.argument<ByteArray>("data")
|
||||
if (data != null) pushInternal(data)
|
||||
result.success(null)
|
||||
}
|
||||
|
||||
"stop" -> {
|
||||
pendingStartResult?.error("CANCELLED", "BLE relay host start cancelled", null)
|
||||
pendingStartResult = null
|
||||
stopInternal()
|
||||
result.success(null)
|
||||
}
|
||||
"isSupported" -> result.success(bluetoothAdapter != null && bluetoothAdapter!!.isMultipleAdvertisementSupported)
|
||||
|
||||
"isSupported" -> result.success(
|
||||
bluetoothAdapter != null && bluetoothAdapter!!.isMultipleAdvertisementSupported,
|
||||
)
|
||||
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
@@ -263,6 +279,7 @@ class BleRelayHostPlugin : FlutterPlugin, MethodCallHandler {
|
||||
pendingStartResult?.success(null)
|
||||
pendingStartResult = null
|
||||
}
|
||||
|
||||
override fun onStartFailure(errorCode: Int) {
|
||||
Log.e(TAG, "BLE advertising failed: $errorCode")
|
||||
pendingStartResult?.error(
|
||||
@@ -274,4 +291,4 @@ class BleRelayHostPlugin : FlutterPlugin, MethodCallHandler {
|
||||
stopInternal()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user