看板 AndroidDev 關於我們 聯絡資訊
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
givemepass:寫一個Listener 如果有值就notify 11/17 11:43
sorkayi:我記得會有 handle 在抓值 11/17 19:29
fake01:givemepass 大大 那如何判斷 一有值?? 11/21 04:37