@@ -770,14 +770,15 @@ function initBluetoothGattCallback() {
770770 * @params value - byte: the value of the characteristic This value cannot be null. This will "status" in Android API level < 33.
771771 * @param status [number] - GATT_SUCCESS if the read operation was completed successfully.
772772 */
773- onCharacteristicRead ( gatt : android . bluetooth . BluetoothGatt , characteristic : android . bluetooth . BluetoothGattCharacteristic , value : any , status : number ) {
773+ onCharacteristicRead (
774+ gatt : android . bluetooth . BluetoothGatt ,
775+ characteristic : android . bluetooth . BluetoothGattCharacteristic ,
776+ valueOrStatus : androidNative . Array < number > | number ,
777+ status ?: number
778+ ) {
774779 this . subDelegates . forEach ( ( d ) => {
775780 if ( d . onCharacteristicRead ) {
776- if ( sdkVersion < 33 ) {
777- d . onCharacteristicRead ( gatt , characteristic , value ) ;
778- } else {
779- d . onCharacteristicRead ( gatt , characteristic , status ) ;
780- }
781+ d . onCharacteristicRead ( gatt , characteristic , valueOrStatus as androidNative . Array < number > , status ) ;
781782 }
782783 } ) ;
783784 }
@@ -1866,7 +1867,12 @@ export class Bluetooth extends BluetoothCommon {
18661867 this . attachSubDelegate (
18671868 { methodName, args, resolve, reject } ,
18681869 ( clearListeners , onError ) => ( {
1869- onCharacteristicRead : ( gatt : android . bluetooth . BluetoothGatt , characteristic : android . bluetooth . BluetoothGattCharacteristic , status : number ) => {
1870+ onCharacteristicRead : (
1871+ gatt : android . bluetooth . BluetoothGatt ,
1872+ characteristic : android . bluetooth . BluetoothGattCharacteristic ,
1873+ valueOrStatus : androidNative . Array < number > | number ,
1874+ status ?: number
1875+ ) => {
18701876 const device = gatt . getDevice ( ) ;
18711877 let UUID : string = null ;
18721878 if ( device == null ) {
@@ -1876,13 +1882,15 @@ export class Bluetooth extends BluetoothCommon {
18761882 }
18771883 const cUUID = uuidToString ( characteristic . getUuid ( ) ) ;
18781884 const sUUID = uuidToString ( characteristic . getService ( ) . getUuid ( ) ) ;
1885+ const isReturningValue = sdkVersion >= 33 ;
1886+ const actualStatus = isReturningValue ? status : ( valueOrStatus as number ) ;
18791887 if ( Trace . isEnabled ( ) ) {
1880- CLog ( CLogTypes . info , `${ methodName } ---- got result peripheralUUID:${ pUUID } serviceUUID:${ sUUID } characteristicUUID:${ cUUID } status:${ status } ` ) ;
1888+ CLog ( CLogTypes . info , `${ methodName } ---- got result peripheralUUID:${ pUUID } serviceUUID:${ sUUID } characteristicUUID:${ cUUID } status:${ actualStatus } ` ) ;
18811889 }
18821890 if ( UUID === pUUID && cUUID === args . characteristicUUID && sUUID === args . serviceUUID ) {
18831891 timeoutTimer && clearTimeout ( timeoutTimer ) ;
1884- if ( status === GATT_SUCCESS ) {
1885- const value = characteristic . getValue ( ) ;
1892+ if ( actualStatus === GATT_SUCCESS ) {
1893+ const value = isReturningValue ? ( valueOrStatus as androidNative . Array < number > ) : characteristic . getValue ( ) ;
18861894 resolve ( {
18871895 android : value ,
18881896 value : byteArrayToBuffer ( value ) ,
@@ -1895,7 +1903,7 @@ export class Bluetooth extends BluetoothCommon {
18951903 onError (
18961904 new BluetoothError ( BluetoothCommon . msg_error_function_call , {
18971905 method : 'readCharacteristic' ,
1898- status ,
1906+ actualStatus ,
18991907 arguments : args
19001908 } )
19011909 ) ;
0 commit comments