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

[Android] - setNotifiable throw PlatformException(error, Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' #146

Open
riorizki opened this issue Jun 17, 2023 · 1 comment

Comments

@riorizki
Copy link

riorizki commented Jun 17, 2023

Hi,

i got ble device with 2 characteristic in 1 service
each characteristic got different properties (1 for notify and 1 for write)

when i set the setNotifable to notification like code below i got error

QuickBlue.setNotifiable(
  ble.deviceId,
  service,
  '0000ffe1-0000-1000-8000-00805f9b34fb',
  BleInputProperty.notification,
);
E/MethodChannel#quick_blue/method(26826): Failed to handle method call
E/MethodChannel#quick_blue/method(26826): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
E/MethodChannel#quick_blue/method(26826): 	at com.example.quick_blue.QuickBluePluginKt.setNotifiable(QuickBluePlugin.kt:296)
E/MethodChannel#quick_blue/method(26826): 	at com.example.quick_blue.QuickBluePlugin.onMethodCall(QuickBluePlugin.kt:111)
E/MethodChannel#quick_blue/method(26826): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/MethodChannel#quick_blue/method(26826): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#quick_blue/method(26826): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#quick_blue/method(26826): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#quick_blue/method(26826): 	at android.os.Handler.handleCallback(Handler.java:883)
E/MethodChannel#quick_blue/method(26826): 	at android.os.Handler.dispatchMessage(Handler.java:100)
E/MethodChannel#quick_blue/method(26826): 	at android.os.Looper.loop(Looper.java:214)
E/MethodChannel#quick_blue/method(26826): 	at android.app.ActivityThread.main(ActivityThread.java:7356)

E-flutter (26826): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
E/flutter (26826): 	at com.example.quick_blue.QuickBluePluginKt.setNotifiable(QuickBluePlugin.kt:296)
E/flutter (26826): 	at com.example.quick_blue.QuickBluePlugin.onMethodCall(QuickBluePlugin.kt:111)
E/flutter (26826): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/flutter (26826): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (26826): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/flutter (26826): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (26826): 	at android.os.Handler.handleCallback(Handler.java:883)
E/flutter (26826): 	at android.os.Handler.dispatchMessage(Handler.java:100)
E/flutter (26826): 	at android.os.Looper.loop(Looper.java:214)
E/flutter (26826): 	at android.app.ActivityThread.main(ActivityThread.java:7356)
E/flutter (26826): 	at java.lang.reflect.Method.invoke(Native Method)
E/flutter (26826): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
E/flutter (26826): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/flutter (26826): )
E/flutter (26826): #0      StandardMethodCodec.decodeEnvelope
message_codecs.dart:652
E/flutter (26826): #1      MethodChannel._invokeMethod
platform_channel.dart:310
E/flutter (26826): <asynchonous suspension>
E/flutter (26826):

this is the logcat of discover service

D/BluetoothGatt(25138): discoverServices() - device: 20:22:08:25:10:0C
D/BluetoothGatt(25138): onSearchComplete() = Device=20:22:08:25:10:0C Status=0
V/QuickBluePlugin(25138): onServicesDiscovered 20:22:08:25:10:0C 0
2 V/QuickBluePlugin(25138): Service 0000ffe0-0000-1000-8000-00805f9b34fb
V/QuickBluePlugin(25138):     Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb
V/QuickBluePlugin(25138):         Descriptor 00002902-0000-1000-8000-00805f9b34fb

How can i setNotifiable so i can receive to value from ble ?

Thank you

@SahilSharma2710
Copy link

hey @riorizki i have counter question QuickBlue.setNotifiable(deviceId, serviceId, characteristicId, true); , how we determine the values of serviceId & characteristics ?? I struggling with same problem i guess

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

2 participants