sockets - Can't read data from bluetooth medical device and android -



sockets - Can't read data from bluetooth medical device and android -

i want connect android app pulse oximeter (sat 300 bt), i'm encountering problems when phone call inputstrem.read(), method never returns (i know blocking read), think because medical device never gives me inputstream.

i've read device needs receive output message before send messages client, if case, don't know message send.

this code i've:

public class bluetoothactivity extends baseactivity { private static final string tag = "bluetoothactivity"; private static final boolean d = true; private bluetoothadapter bluetoothadapter; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); bluetoothadapter = bluetoothadapter.getdefaultadapter(); if (bluetoothadapter.isenabled()) { set<bluetoothdevice> devicesavailable = bluetoothadapter.getbondeddevices(); if (devicesavailable.size() > 0) { (bluetoothdevice device : devicesavailable) { log.d(tag, device.getname() + " " + device.getaddress() + "\n"); } } if (!devicesavailable.isempty()) { askusertopick(devicesavailable); } } } private void askusertopick(set<bluetoothdevice> devicesavailable) { (iterator iterator = devicesavailable.iterator(); iterator.hasnext();) { bluetoothdevice bluetoothdevice = (bluetoothdevice) iterator.next(); if (bluetoothdevice.getaddress().equalsignorecase("00:0c:b6:02:38:80")) { seek { opensocket(bluetoothdevice); } grab (ioexception e) { e.printstacktrace(); } } } } private void opensocket(bluetoothdevice bluetoothdevice) throws ioexception { final connectrunnable connector = new connectrunnable(bluetoothdevice); connector.start(); } private class connectrunnable extends thread { private inputstream inputstream; private bluetoothsocket socket; private final bluetoothdevice bluetoothdevice; public connectrunnable(bluetoothdevice bluetoothdevice) { this.bluetoothdevice = bluetoothdevice; } public void run() { seek { uuid uuid = bluetoothdevice.getuuids()[0].getuuid(); bluetoothsocket socket = bluetoothdevice.createrfcommsockettoservicerecord(uuid); socket.connect(); log.d(tag, "connected"); seek { inputstream inputstream = socket.getinputstream(); readinputstream(inputstream); inputstream.close(); socket.close(); } grab (exception e) { log.d(tag, "connect(): error attaching i/o streams socket. msg=" + e.getmessage()); } } grab (securityexception e) { log.e(tag, "secex", e); } grab (illegalargumentexception e) { log.e(tag, "iargex", e); } grab (ioexception e) { log.e(tag, "ioex", e); } } private void readinputstream(inputstream inputstream) throws ioexception { stringbuilder builder = new stringbuilder(); byte[] buffer = new byte[300]; int bytes = inputstream.read(buffer); builder.append(new string(buffer, 0, bytes)); } }

}

android sockets bluetooth inputstream

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -