[問題] android 藍芽 接值
private class ConnectedThread extends Thread {
public void run() {
byte[] buffer = new byte[2048];
int bytes = 0,totalb=0;
String temp ="",temp2="";
byte[] Bytes;
int num = 0;
byte[] array;
int ary[] = {2};
//String readMessage= new String();
// Keep listening to the InputStream while connected
try {
mmInStream = socket.getInputStream();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
while (true) {
try {
// if((bytes = mmInStream.read(buffer))==-1)
bytes = mmInStream.read(buffer,0,17);
temp = new String(buffer , 0, bytes,"GBK");
// textview04.setText(readMessage);
} catch (IOException e) {
// break;
}
totalb +=bytes;
TotalB += Integer.toString(bytes);
readMessage += temp;
updateTextView(TotalB);
}
}
}
我想問的問題是,藍芽接值這邊,是用while迴圈不斷抓值,
但是這會有一個問題,我想要一次抓完17個byte,因為傳值那端 也只會丟17個byte
while抓 會只能 片段, 我該如何寫才能判斷 對方已經有值丟進來 ,我才抓
這樣就不用while
聽不懂的話 我會再說明清楚
謝謝各位了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.135.91
推
11/17 11:43, , 1F
11/17 11:43, 1F
推
11/17 19:29, , 2F
11/17 19:29, 2F
→
11/21 04:37, , 3F
11/21 04:37, 3F
AndroidDev 近期熱門文章
PTT數位生活區 即時熱門文章