[問題] android 藍芽 接值

看板AndroidDev作者 (ya da)時間13年前 (2011/11/17 01:44), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/1
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
寫一個Listener 如果有值就notify
11/17 11:43, 1F

11/17 19:29, , 2F
我記得會有 handle 在抓值
11/17 19:29, 2F

11/21 04:37, , 3F
givemepass 大大 那如何判斷 一有值??
11/21 04:37, 3F
文章代碼(AID): #1Em_PWrc (AndroidDev)
文章代碼(AID): #1Em_PWrc (AndroidDev)