Android 蓝牙插座,读写字符串
如何通过蓝牙插座输出和读取字符串。现在,它打印正在发送的字节值,即字符0-255的数目。所以“嗨”是2,“再见”是3。以下是我的读写功能:Android 蓝牙插座,读写字符串,android,bluetooth,Android,Bluetooth,如何通过蓝牙插座输出和读取字符串。现在,它打印正在发送的字节值,即字符0-255的数目。所以“嗨”是2,“再见”是3。以下是我的读写功能: public void read() { byte buffer[] = new byte[1024]; final int bytes; try { bytes = iStream.read(buffer); acti
public void read() {
byte buffer[] = new byte[1024];
final int bytes;
try {
bytes = iStream.read(buffer);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateTView(bytes);
}
});
Log.i("WTF",String.valueOf(bytes));
} catch(IOException e) {
//TODO: something
}
}
public void writeText(byte bytes[]) {
try {
oStream.write(bytes);
} catch(IOException e) {
//TODO: something
}
}
在后台线程中执行此操作
byte[] buffer = new byte[1024];
bytes = input.read(buffer);
String readMessage = new String(buffer, 0, bytes);
// Send the obtained bytes to the UI Activity
System.out.println(readMessage);
byte[] buffer = new byte[1024];
bytes = input.read(buffer);
String readMessage = new String(buffer, 0, bytes);
// Send the obtained bytes to the UI Activity
System.out.println(readMessage);