내 안드로이드 응용 프로그램이 블루투스 연결을 통해 폴라 심장 박동 모니터에서 데이터를 가져 오는 중입니다. 내 문제는 내가 그런 문자열을 얻고 있다는 것입니다 : 폴라 심박수 모니터에서 적절한 값을 얻는 방법
데이터를 얻기위한 나의 코드 :
을 : 나는 몇 가지 방법이 줄을 변경하려하지만 난 여전히 잘못된 데이터를 얻고final Handler handler = new Handler();
final byte delimiter = 10; //This is the ASCII code for a newline character
stopWorker = false;
readBufferPosition = 0;
readBuffer = new byte[1024];
workerThread = new Thread(new Runnable()
{
public void run()
{
while(!Thread.currentThread().isInterrupted() && !stopWorker)
{
try
{
int bytesAvailable = mmInputStream.available();
if(bytesAvailable > 0)
{
byte[] packetBytes = new byte[bytesAvailable];
mmInputStream.read(packetBytes);
for(int i=0;i<bytesAvailable;i++)
{
byte b = packetBytes[i];
if(b == delimiter)
{
byte[] encodedBytes = new byte[readBufferPosition];
// System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
final String data = new String(encodedBytes, "ASCII");
readBufferPosition = 0;
handler.post(new Runnable()
{
public void run()
{
pulsText.setText(data);
}
});
}
else
{
readBuffer[readBufferPosition++] = b;
}
}
}
}
catch (IOException ex)
{
stopWorker = true;
}
}
}
});
workerThread.start();
final String data = new String(encodedBytes, "ASCII");
이 문제를 어떻게 해결할 수 있습니까?
도와주세요!
렌더링 된 문자열이 아닌 원시 바이트 값을 보았습니까? –
문자가 인쇄 가능 범위 위에있는 것처럼 보입니다. 문자가 아닌 정수로보아야하며 더 이상 이해가되는지 확인해야합니다. – twain249
@erni 어떻게 문제를 해결 했습니까? – Hunt