Android Question Serial1Connected event - Android 7

Arf

Well-Known Member
Licensed User
Longtime User
I've been trying to dig into the pairing problems I've been having on this Android 7 tablet.
I can now see what's going wrong, I think.
When I 'serial.Connect' to a device that has not previously been paired, I get a 'serial_Connected' event with FALSE as the success report (this happens only once I have clicked the PAIR? OK button), and immediately after that I get another one with TRUE as the success report.

I don't believe this was happening with prior android versions. My project only really deal with one failure or success report for each connection attempt, so this behaviour is causing me grief.

Is this False, True behaviour expected?

Thanks
 

Arf

Well-Known Member
Licensed User
Longtime User
Ah OK. I've fgound that indeed, 'Connect' is being called twice.
This is because 'Connect' is called from within DiscoveryFinished.
I can see that I am getting two DiscoveryFinished events, even after cancelling discovery. The second one occurs the moment I press the 'Pair? - OK' button and my activity is resumed (after being paused buy the system 'OK to pair?' dialog).

** Activity (main) Pause, UserClosed = false **
** Activity (settings) Create, isFirst = true **
** Activity (settings) Resume **
stop listening
*13:55:31:866::I:Units_Comms:stop listening
discovery started
Spiro_001003:D8:80:39:F0:D1:22
discovery cancelled
:08:61:E2:46:CA:A9
:D0:03:4B:49:6A:2E
*13:55:45:621::I:Units_Comms:Spiro_001003:D8:80:39:F0:D1:22
*13:55:46:078::I:Units_Comms::08:61:E2:46:CA:A9
*13:55:46:101::I:Units_Comms::D0:03:4B:49:6A:2E
entering DISCOVERY FINISHED
Unit is not paired
connect direct to D8:80:39:F0:D1:22
*13:55:46:203::I:Units_Comms:connect direct to D8:80:39:F0:D1:22
** Activity (settings) Pause, UserClosed = false **
*** Service (btpair) Create ***
** Service (btpair) Start **
** Service (btpair) Start **
Unit is not paired
** Activity (settings) Resume **
entering DISCOVERY FINISHED
Unit is not paired
connect direct to D8:80:39:F0:D1:22
connected: false
let's hope another connection follows this one
*13:55:59:152::I:Units_Comms:connect direct to D8:80:39:F0:D1:22
*13:55:59:232::I:Units_Comms:connected: false
connected: true
loc3 java.io.IOException: bt socket closed, read return: -1
admin statechange. old = STATE_ON new = STATE_TURNING_OFF
*13:55:59:274::I:Units_Comms:connected: true
*13:55:59:503::I:Units_Comms:admin statechange. old = STATE_ON new = STATE_TURNING_OFF
admin statechange. old = STATE_TURNING_OFF new = STATE_OFF
admin statechange. old = STATE_OFF new = STATE_TURNING_ON
admin statechange. old = STATE_TURNING_ON new = STATE_ON
StartListen2
listening
*13:55:59:573::I:Units_Comms:admin statechange. old = STATE_TURNING_OFF new = STATE_OFF
*13:55:59:593::I:Units_Comms:admin statechange. old = STATE_OFF new = STATE_TURNING_ON
*13:55:59:768::I:Units_Comms:admin statechange. old = STATE_TURNING_ON new = STATE_ON
*13:55:59:772::I:Units_Comms:listening
stop listening

Is that expected? I am definitely only starting one discovery and cancelling it.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
I've had a few issues with this before actually, so what I've done now is set a flag 'IgnoreDiscovery' to True whenever a connection to a discovered is attempted from within the DiscoveryFinished function, seems to work well.
 
Upvote 0
Top