Skip to content

Commit 898056d

Browse files
committed
chore(android): native data
1 parent ae5683b commit 898056d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

src/typings/android.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
}

0 commit comments

Comments
 (0)