Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling js method onCharacteristicWrite failed #23

Open
thiamugb opened this issue Nov 5, 2018 · 2 comments
Open

Calling js method onCharacteristicWrite failed #23

thiamugb opened this issue Nov 5, 2018 · 2 comments

Comments

@thiamugb
Copy link

thiamugb commented Nov 5, 2018

Hi,
I want to write some data to my characteristics alert like
bluetooth.writeWithoutResponse({
serviceUUID: '1802',
characteristicUUID: '2a06',
peripheralUUID: this.deviceUUID,
value: '0x01'
})

I have an error like " Error: java.lang.NoSuchFieldError: no "Landroid/os/Parcelable$Creator;" field "CREATOR" in class "Landroid/bluetooth/BluetoothGattCharacteristic;" or its superclasses "
Or if i use value : 0x01 i have 'Error in Bluetooth.writeWithoutResponse: Error: Expect integer value as a second argument."
I want to know if someone have the same error.
Need help or issues
Best Regards.

@mtchoy
Copy link

mtchoy commented Mar 27, 2019

Yes, i have the same error with the Android preview app.

@aitch0083
Copy link

aitch0083 commented Jun 23, 2019

I also had the same problem when I deployed the app on Android 5.1.1 and tried to write the message to the device. I found the workaround. Find node_modules/nativescript-bluetooth/bluetooth.android.js. Find method onCharacteristicWrite, then change the body of the method to the following:

onCharacteristicWrite: function (bluetoothGatt, bluetoothGattCharacteristic, status) {
    
    if (Bluetooth.characteristicLogging) {
      console.log("------- _MyGattCallback.onCharacteristicWrite");
    }

    var device       = bluetoothGatt.getDevice();
    var sdevice      = device.getAddress();
    var target       = Bluetooth._connections[sdevice];
    var stateObject  = null;
    var ignore_bGatt = android.os.Build.VERSION.SDK_INT < 23 ? true : false;

    if(target.state === 'connecting'){
      stateObject = target;
    } else {
      return;
    }

    if (!stateObject) {
      Bluetooth._disconnect(bluetoothGatt);
      return;
    }

    if (!ignore_bGatt && Bluetooth.characteristicLogging) {
      console.log(bluetoothGattCharacteristic);
    }

    if (stateObject.onWritePromise) {
      stateObject.onWritePromise({
        characteristicUUID: !ignore_bGatt ? bluetoothGattCharacteristic.getUuid() : 'N/A'
      });
    }
  },

The problem is bluetoothGattCharacteristic. For SDK_INT < 23 , bluetoothGattCharacteristic will throw this exception during runtime. It probably needs the team to fix this. I hope this workaround would help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants