作者fake01 (ya da)
看板AndroidDev
标题[问题] android 蓝芽 接值
时间Thu Nov 17 01:43:58 2011
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
1F:推 givemepass:写一个Listener 如果有值就notify 11/17 11:43
2F:推 sorkayi:我记得会有 handle 在抓值 11/17 19:29
3F:→ fake01:givemepass 大大 那如何判断 一有值?? 11/21 04:37