Android Question Bluetooth and Android 11 not connecting

mscientist33

Active Member
Licensed User
I have a serial bluetooth device that I can pair with my Android 11 phone. I am using the code from the example "chat" app to make my bluetooth connection. I can connect and run my app with anything but Android 11. Once I hit connect it jumps straight to "disconnected". This is what I get in the log.
This is the serial device I am using: http://www.usconverters.com/bluetooth-serial-adapter?zenid=f80b592983966cac53a604d43eb66f4c.

The phone is manually paired with the device before the app is ran.

This is my manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136

Manifest block:
AddManifestText(

<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="30"/>

<supports-screens android:largeScreens="true"

    android:normalScreens="true"

    android:smallScreens="true"

    android:anyDensity="true"/>)

SetApplicationAttribute(android:icon, "@drawable/icon")

SetApplicationAttribute(android:label, "$LABEL$")

CreateResourceFromFile(Macro, Themes.LightTheme)

AddPermission(android.permission.BLUETOOTH_ADMIN)

AddPermission(android.permission.BLUETOOTH)

AddPermission(android.permission.ACCESS_FINE_LOCATION)

AddPermission(permission.ACCESS_BACKGROUND_LOCATION)

This is my sub from the example:
My sub:
Public Sub ListenForConnections

    'this intent makes the device discoverable for 300 seconds.

    Dim i As Intent

    i.Initialize("android.bluetooth.adapter.action.REQUEST_DISCOVERABLE", "")

    i.PutExtra("android.bluetooth.adapter.extra.DISCOVERABLE_DURATION", 300)

    StartActivity(i)

    serial.Listen

End Sub


I send data to that and then to an xbee radio.

(IOException) java.io.IOException: read failed, socket might closed or timeout, read ret: -1


I have added AddPermission(android.permission.ACCESS_FINE_LOCATION) to my manifest. I have also tried both android:targetSdkVersion="29" and also tried the "30" that seems to be required in google play (please correct me if I am wrong there... I am new to this).

Anything else I need to add for this to work in Android 11?
 
Last edited:

f0raster0

Well-Known Member
Licensed User
Longtime User
try testing using this example: (it works for me)

also use the App nRF connect to test the communication is correct between your Smartphone and your Hardware
 
Upvote 0

mscientist33

Active Member
Licensed User
try testing using this example: (it works for me)

also use the App nRF connect to test the communication is correct between your Smartphone and your Hardware
Will it work even if the Serial Adapter is not BLE?
 
Upvote 0

mscientist33

Active Member
Licensed User
No.

Using activities with Bluetooth or any other network feature is a big mistake.
This example works with Android 11: https://www.b4x.com/android/forum/threads/b4xpages-bluetooth-chat-example.119014/#content
The test app did connect. Thank you. It took a little learning and playing around to understand the b4xpages vs activities but it now works. It still gives the error every now and again. I was trying to hit the scan button and have it automatically connect when it found the correct adapter by Name but it will error out every time that way. Now the only issue is that on Android 11 phones, during discovery it always adds duplicates of everything it finds. It doesn't do that on 10 and below. I need to figure out how to stop the discovery once the correct adapter is found so it doesn't take so long waiting on it to get everything it finds.
 
Last edited:
Upvote 0
Top