Hi, I wrote a simple test driver to test the bluetooth apis. Anyone can
verify whether I am using the API correctly? Everything seems good but no
data read :-(
===========================================================================
// before calling the following, inquiry scan successfully returned, and the
remote device is pre-paired.
private boolean doTestConnection() {
Log.d("SwxBtCommImpl", "doTestConnection");
String btAddr = "00:08:1B:CA:C7:29";
BluetoothDevice btdev =
BluetoothAdapterImpl.getInstance().getRemoteDevice(btAddr);
// widcom using the following GUID
// 00001101-0000-1000-8000-00805F9B34FB
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
try {
BluetoothSocket btsocket =
btdev.createRfcommSocketToServiceRecord(uuid);
btsocket.connect();
Log.d("SwxBtCommImpl", "connected");
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
InputStream instream = btsocket.getInputStream();
Log.d("", "getInputStream");
byte[] data = new byte[512];
for (int i = 0; i < 20; i++) {
int numOfAvailable = instream.available();
Log.d("SwxBtCommImpl", "read " + i + ": " + numOfAvailable + "
bytes");
if(numOfAvailable > 0) {
int numOfRead = instream.read(data);
Log.d("SwxBtCommImpl", new String(data) + "-" + numOfRead);
} else {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
instream.close();
instream = null;
btsocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("", "bt connection failed", e);
}
return true;
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en