afarley
afarley

Reputation: 815

Why does Android Bluetooth stop receiving bytes after a few minutes?

I'm having trouble maintaining a Bluetooth connection (from Android to a device I'm developing) for longer than a few minutes.

The scenario is:

  1. Device is paired successfully.
  2. Device transmits to Android for somewhere between 1-7 minutes (varies by device or possibly Android version).
  3. Android stops receiving bytes although device is still transmitting.

So: why does Android BT stop receiving?

This is very similar to the issue/observation described in bboydflo's answer to this question: Application using bluetooth SPP profile not working after update from Android 4.2 to Android 4.3

Some more background:

I would like to pre-emptively address reasons that this question may be closed:

Upvotes: 1

Views: 1676

Answers (1)

afarley
afarley

Reputation: 815

Ok, I have a partial answer for this one. First, a bit more background:

  • I was running the BT stream polling on a thread which executed a runnable every 2s
  • The buffer being used to read the stream was 1024 elements long

I had a suspicious that this might be some background buffer running out of space. So, I changed the 2s to 500ms and the 1024-length to 10024. Now, I've had about 20 minutes of connectivity without any trouble (and still going).

It would be nice to find the smoking gun for this. I initially thought that stream.Available() would be sufficient to tell if a buffer was getting filled up, but in this scenario, stream.Available() is actually returning 0 when the Android device stops receiving. So I'm not really sure which queue to check to prove that this issue is related to a buffer becoming filled.

Upvotes: 1

Related Questions