Click here to Skip to main content
15,745,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When we call the bluetooth BLE manager for connection was success but it is getting unpair and disconnected frequently on android phone.

What I have tried:

fun isDevicePaired(name: String) : Boolean {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            if (ActivityCompat.checkSelfPermission(
                ) != PackageManager.PERMISSION_GRANTED
            ) {
                // TODO: Consider calling
                return false
        lateinit var mBluetoothAdapter: BluetoothAdapter

        try {
            mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
        } catch (e: Exception) {
            return false

        var pairedDevices: Set<BluetoothDevice>? = mBluetoothAdapter.bondedDevices

        for (device in pairedDevices?.toList() ?: listOf()) {
            if (!
                if (
                    return true

        return false
Gerry Schmitz 15-Feb-23 18:24pm    
Nothing happens "randomly". You need to find a pattern and a cause. Android only? (apparently, by your post). So, one size doesn't fit all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900