android - how to send Data to a BLE server -
i able connect ble device following https://developer.android.com/samples/bluetoothlegatt/src/com.example.android.bluetoothlegatt/bluetoothleservice.html ,but unable find how send data ? callback implementation follows :-
private final bluetoothgattcallback gattcallback = new bluetoothgattcallback() { @override public void onconnectionstatechange(bluetoothgatt gatt, int status, int newstate) { switch (newstate) { case bluetoothprofile.state_connected: gatt.discoverservices(); break; case bluetoothprofile.state_disconnected: break; default: system.out.println("device 3: other_state !!"); } } @override public void onservicesdiscovered(bluetoothgatt gatt, int status) { list<bluetoothgattservice> services = gatt.getservices(); gatt.readcharacteristic(services.get(1).getcharacteristics().get (0)); } @override public void oncharacteristicread(bluetoothgatt gatt, bluetoothgattcharacteristic characteristic, int status) { system.out.println("oncharacteristicread"+characteristic.tostring()); if (status == bluetoothgatt.gatt_success) { broadcastupdate(action_data_available, characteristic); } } @override public void oncharacteristicchanged(bluetoothgatt gatt, final bluetoothgattcharacteristic characteristic) { //read characteristic data byte[] data = characteristic.getvalue(); } };
oncharacteristicread function not executing. send data have call mgatt.writecharacteristic(my_characteristic); unable understand how initialize my_characteristic object ?
Comments
Post a Comment