Android Question Bluetooth connection android 14

ravi93

New Member
Hii,
I am facing an issue to connect paired Bluetooth device in android 14, Please help me to find proper solution

Request permission:
Private rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
rp.CheckAndRequest("android.permission.BLUETOOTH_CONNECT")
rp.CheckAndRequest("android.permission.BLUETOOTH_SCAN")
rp.CheckAndRequest("android.permission.ACCESS_FINE_LOCATION")

Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = True Then
        Log(rp.GetSafeDirDefaultExternal(""))
    End If


Bluetooth connection:
private Sub ListViewPairedDevice_ItemClick(Position As Int, Value As Object)
    Dim bluetoothMac As String = PairedDevices.Get(Value)
    device = bluetoothMac
    connecToDevice(bluetoothMac)
End Sub

'This method will try to connect selected bluetooth devices
private Sub connecToDevice(bluetoothMac As String)
    ButtonConnect.Enabled=False
    Try
        serial.Connect(bluetoothMac)
        ToastMessageShow("Device: " & device & "   connecting",False)
    Catch
        Dim ex As Exception
        ex = LastException
        Log("Exception: " & ex.Message)
        ToastMessageShow("Device not available",True)
    End Try
End Sub

Sub Serial_Connected (Success As Boolean)
    Try
        If Success Then
            Log("Device Connection Successful")
        Else
            Log("Device Connection Failed: " & LastException)
            ToastMessageShow("Device: " & device & "  not connected",True)
            timerConnect.Enabled=False
        End If
    Catch
        Log(LastException)
    End Try

    ListViewPairedDevice.Visible=False
End Sub

If i am trying to connect with paired device it throw exception is:
Device Connection Failed: (IOException) java.io.IOException: read failed, socket might closed or timeout, read ret: -1
 

ravi93

New Member
Thanks for your Response.

I have already followed the link that you have shared with me, and it's helpful to me.
But now my question is, in the chat app, Bluetooth is only connected if both devices have the same application, but in my scenario, I have to connect 3rd party Bluetooth device which is not a tablet or mobile device may be some audio device so what can I do?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…