Android Question Bluetooth connection - interrupted itself - on new Android(>=4.4.2)

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, please very much for advice,

I was recognized, that my app close the bluetooth connenction itself. It is happening
on newer version of Android and on some phones.


I am using:
B4X:
    Dim admin As BluetoothAdmin
               Dim Serial1 As Serial
               Dim AStream As AsyncStreams

After some time the app disconnect my bluetooth connection.
It happen the same as I can do with command:
B4X:
serialservice.astream.Close
Serial1.Disconnect

Please why is this happening and how can I keep connection? Do you have experience?

This situation exist only on some phones (for example Samsung galaxy j5, s4mini, Huawei Honor)
And Android 4.4.2 and higher

Please very much for advice,
best regards

p4ppc
 
Last edited:

petr4ppc

Well-Known Member
Licensed User
Longtime User
Erel,

I have this:
B4X:
Log("Error ASTREAM: " & LastException)
Log ("TERMINATED")

in

B4X:
Sub Astream_Error
Sub AStream_Terminated

after interruption of bluetooth connection here are not Logs,
so the events do not fire...

p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Erel,

I must correct information. I am checking LOGS from service and yes, now I can see this:
B4X:
a) first phone
Error ASTREAM: (IOException) java.io.IOException: bt socket closed, read return: -1
or
Error ASTREAM: (IOException) java.io.IOException: socket closed

b) second phone
Error ASTREAM: (IOException) java.io.IOException: Broken pipe

I am using in service this:
B4X:
Dim AStream As AsyncStreams
Sub Service_Create
AStream.Initialize(Main.Serial1.InputStream, Main.Serial1.OutputStream, "AStream")
End Sub

It is new situation with bluetooth connection in phones.

For example with:
a)
Bluetooth v4.0, A2DP, EDR, LE
Android 4.2.2
is with connection everything OK
b)
Bluetooth v4.0, A2DP, EDR
Android OS, v4.4.2
is connection interrupted itself


Please what does it mean, what can I do? After few days I dont know where i am doing mistake.
I dont know, how can I customize ASTREAM (in service) to new phones.

***If I am trying standard b4a example = ChatActivity - Bluetooth app, I see the same situation = the connection is interrupted after some time.

Best regards,

p4ppc
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
I belive you, it is sad situation with this unstable bluetooth devices.

I have the experience, that connection is broken often after first sendindg data-pocket from phone.
It is not possible to reconnect bluetooth connection after sendindg each data-pocket from phone.

Best regards
p4ppc
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Erel,

Yes - I am using bluetooth chat as is.

I am finding solution.

I found similar app like standard b4a example = ChatActivity - Bluetooth app
here is similar and very simple bluetooth chat on google play :

https://play.google.com/store/apps/details?id=appinventor.ai_g916414.Bluetooth_CHAT_REMOTE_CONTROL
with this app is everything OK.
The app create bluetooth connection and it keep the connection - here is not itself interruption.

What does it mean, please - it is possible to do something with b4a bluetooth chat?
Best regards
p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Erel, it was before some days, I wrote:
"....that my app close the bluetooth connenction itself"

then I spent some days with finding solution

And now I am trying only bluetooth chat, as I wrote:
***If I am trying standard b4a example = ChatActivity - Bluetooth app, I see the same situation = the connection is interrupted after some time.

And now I am trying only - connection, only with bluetooth chat
https://www.b4x.com/android/forum/t...admin-and-insecure-connections.10925/#content
I have Library: Serial(version: 1.23)

Best regards
p4ppc

 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Excuse me, I dont know if you mean standard logs which I get in LOGs window:

Here are LOGs from LOG window:

B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
MY-PC:00:25:52:32:A2:30
connected: true
** Activity (main) Pause, UserClosed = false **
** Activity (chatactivity) Create, isFirst = true **
** Activity (chatactivity) Resume **
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Erel,

I am testing it with connection between
1) mobile and bluetooth device ( bluetooth toy ) - it is not OK, the connection is broken after sending data to mobile app
2) mobile and pc with windows 7 - connection is ok

As I wrote - other simply and similar chat apps working OK (i am sending and reading data - this apps hold connection)
but with
b4a bluetooth chat it looks, that connection is broken after receiving data or after some time
(i am still finding my mistake)

I am testing it long time,
p4ppc
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Erel,

it looks, that it it is true.
I am trying B4A chat example asyncstreams in prefix mode and in not prefix mode and with non prefix mode it looks, that it is OK (I am trying it 15 minutes now)

now I am trying to play with this situation and I have recognized
that if I am using THREAD in B4A chat, this error I see again:

B4X:
Error ASTREAM: (IOException) java.io.IOException: bt socket closed, read return: -1
or
Error ASTREAM: (IOException) java.io.IOException: socket closed
or
Error ASTREAM: (IOException) java.io.IOException: Broken pipe

It is possible, that THREAD actions can interrupt the connection of serial port?
I hope, that it is not dumb question from my side..

Thank you very much
Best regards
p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Erel,

In this examle I am trying to control bluetooth via wifi and combine it with TTS fuction. But I stoped work on it for few days and now I am continue...
I will find more informations about it.

Thank you
p4ppc
 
Upvote 0
Top