Witam, potrzebuję pomocy z metodą pobrania danych przez Bluetooth. Otóż poniższy kod jest jak najbardziej prawidłowy natomiast zwraca mi po kolei każdą daną osobno z Arduino, a potrzebuję je wszystkie pod jedną zmienną tj:
Taki dostaję teraz wynik:
09-14 0114.962 17243-17243/com.example.maciej.arduino I/ContentValues: 24.125
09-14 0115.373 17243-17243/com.example.maciej.arduino I/ContentValues: 24.250
09-14 0115.486 17243-17243/com.example.maciej.arduino I/ContentValues: 24.437
A chciałbym coś takiego:
................................ 17243-17243/com.example.maciej.arduino I/ContentValues: 24.12524.25024.437
Moja metoda:
void PobierzDane()
{
final Handler handler = new Handler();
stopThread = false;
buffer = new byte[1024];
Thread thread = new Thread(new Runnable()
{
public void run()
{
while(!Thread.currentThread().isInterrupted() && !stopThread)
{
try
{
int byteCount = inputStream.available();
if(byteCount > 0)
{
byte[] rawBytes = new byte[byteCount];
inputStream.read(rawBytes);
final String string = new String(rawBytes,"UTF-8");
handler.post(new Runnable() {
public void run()
{
Log.i(TAG, string);
sensorView.setText(string);
}
});
}
}
catch (IOException ex)
{
stopThread = true;
}
}
}
});
thread.start();
}
Chciałbym w osobnych TextView wyświetlić wynik z czujników i wymyśliłem sobie to w ten sposób, że mając taką zmienną będę mógł za pomocą metody substring takie coś uzyskać.
Mniej więcej tak to bym widział
public void run()
{
String sensor0 = recDataString.substring(1, 5);
String sensor1 = recDataString.substring(6, 10);
sensorView0.setText(" Czujnik 0 = " + sensor0);
sensorView1.setText(" Czujnik 1 = " + sensor1);
}
Nie mogę sobie z tym poradzić. Z góry dziękuję za pomoc.