omaraflak / Bluetooth-Library

Bluetooth client library for Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sending raw buffer (0 - 255)

dobraMorda opened this issue · comments

Hello!

I need to send over bluetooth spp raw buffer (variables with value range: 0 - 255). Is this possible? I was looking for some method like "bluetooth.write(buffer, len)", but nothing to found...

Best regards!
Patryk

Solved.

byte[] bytes = new byte[n];
byte val = 0;
for (int i = 0 ; i<n ; i++){
	val = (byte) (buffer[i] & 0xFF);
	bytes[i] = val;
}
bluetooth.getSocket().getOutputStream().flush();
bluetooth.getSocket().getOutputStream().write(bytes, 0, 256);

Masking bytes and send it over socket output stream.

Hey @dobraMorda, thanks for posting your answer here ! I'm glad you found a solution !