File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
plugin/platforms/android/java/com/nativescript/bluetooth Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .nativescript .bluetooth ;
2+
3+ import android .bluetooth .BluetoothGattCharacteristic ;
4+ import java .lang .String ;
5+ import android .util .Log ;
6+
7+ public class Bluetooth {
8+ public static boolean writeCharStringValue (BluetoothGattCharacteristic characteristic , String value , String encoding ) {
9+ byte [] byteArray = value .getBytes (java .nio .charset .Charset .forName (encoding ));
10+ return characteristic .setValue (byteArray );
11+ }
12+ public static boolean writeCharValue (BluetoothGattCharacteristic characteristic , byte [] value ) {
13+ return characteristic .setValue (value );
14+ }
15+ public static boolean writeCharBufferValue (BluetoothGattCharacteristic characteristic , java .nio .ByteBuffer value ) {
16+ if (!value .isDirect ()) {
17+ return characteristic .setValue (value .array ());
18+ }
19+ byte [] ret = new byte [value .capacity ()];
20+ value .get (ret );
21+ return characteristic .setValue (ret );
22+ }
23+ }
Original file line number Diff line number Diff line change 1+
2+ declare namespace com {
3+ export namespace nativescript {
4+ export namespace bluetooth {
5+ export class Bluetooth {
6+ static writeCharStringValue ( char : android . bluetooth . BluetoothGattCharacteristic , value : string , encoding : string ) ;
7+ static writeCharValue ( char : android . bluetooth . BluetoothGattCharacteristic , value : number [ ] ) ;
8+ static writeCharBufferValue ( char : android . bluetooth . BluetoothGattCharacteristic , value : java . nio . ByteBuffer ) ;
9+ }
10+ }
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments