android - Bluetooth communication on Samsung Galaxy S -


i have android application running on samsung galaxy s phone. application collects sensor data via bluetooth device. part, there no data being sent/received. have set application "auto-reconnects" bluetooth device in case connection "lost".

i observe after 1.5 hours of application running, phone loses connection bluetooth device , auto-reconnect fails.

the sending of sensor data device phone "mission critical". how can ensure connection not lost. solution needs optimal. is, conserve battery, phone needs able sleep / hibernate.

you should listen incoming connections when disconnected (use bluetoothserversocket). should run in foreground service, never stopped. service monitor bluetooth connection state (disconnected, listening, connected) , spam threads each situations (asynctasks).

the listening thread should said in android documentation:

to create listening bluetoothserversocket that's ready incoming connections, use bluetoothadapter.listenusingrfcommwithservicerecord(). call accept() listen incoming connection requests.

to further conserve battery, user can turn off bluetooth - kill listening thread not entire service (go disconnected state). when user turns bluetooth on, service should notice change , restart listening thread.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -