-1
すでにマイクロプロセッサーから受信した表示データをBluetoothで受信しました。それは毎秒実際の電圧と温度の状態を持った私に8ビットのフレームを送ります。ダイナミックディスプレイデータTextView
問題はTextViewが実際のデータを表示しないことです。アプリが読み込まれると、データが表示され、そのように維持されます。データを更新する方法の1つは、アプリを再度読み込むことです。
ハンドラとコードを添付したConnectedThreadを取得しました。
ポーランドのすべてのベスト。
bluetoothIn = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == handlerState) {
String readMessage = (String) msg.obj;
sb.append(readMessage);
int endOfLineIndex = sb.indexOf(";\r\n");
if (endOfLineIndex > 0) {
String dataInPrint = sb.substring(0, endOfLineIndex);
strDlugosc.setText(dataInPrint);
int dataLenght = dataInPrint.length();
strLenght.setText("ilość otrzymanych znakow =" + String.valueOf(dataLenght));
if (sb.charAt(0) == '9') {
String statusb = sb.substring(8,9);
String temperatura = sb.substring(21, 27);
String napiecie = sb.substring(12, 18);
status.setText("Status :" + statusb);
temp_1.setText("TEMPERATURA = " + temperatura + " *C");
nap_1.setText("NAPIECIE = " + napiecie + " V");
}
}
}
private class ConnectedThread extends Thread {
private final InputStream mmInStream;
//creation of the connect thread
public ConnectedThread(BluetoothSocket socket) {
InputStream tmpIn = null;
try {
//Create I/O streams for connection
tmpIn = socket.getInputStream();
} catch (IOException e) { }
mmInStream = tmpIn;
}
public void run() {
byte[] buffer = new byte[1024];
int bytes;
// Keep looping to listen for received messages
while (!ConnectedThread.interrupted()) {
try {
bytes = mmInStream.read(buffer); //read bytes from input buffer
String readMessage = new String(buffer, 0, bytes);
// Send the obtained bytes to the UI Activity via handler
bluetoothIn.obtainMessage(handlerState, bytes, -1, readMessage).sendToTarget();
} catch (IOException e) {
break;
}
}
}