[問題] bluetooth抓取裝置回傳資料

看板AndroidDev作者 (frank)時間8年前 (2015/10/05 01:20), 8年前編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
小弟,我寫了一個App,使用藍芽連接arduino燒錄板,想法是,按一個按鈕,來回傳目前 溫 Android 程式碼,寫在 onClick 裡面 ... InputStream mmInputStream = btSocket.getInputStream(); final byte delimiter = 10; int readBufferPosition = 0; byte[] readBuffer = new byte[1024]; 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, "US-ASCII"); readBufferPosition = 0; }else{ readBuffer[readBufferPosition++] = b; } } } ... 實在不懂這個 getInputStream().read()函式怎麼用。 感謝各位大大 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.253.91.82 ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1443979235.A.ED3.html ※ 編輯: frank910138 (111.253.91.82), 10/05/2015 01:22:53

10/05 15:21, , 1F
所以你的問題是??
10/05 15:21, 1F
我解決了,原先問題是想知道有沒有不使用thread去抓取回傳資料。 getInputStream().read(),想了解這個函式的使用方法 ※ 編輯: frank910138 (1.165.233.161), 10/06/2015 01:00:34
文章代碼(AID): #1M4L_ZxJ (AndroidDev)