fun isDevicePaired(name: String) : Boolean { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (ActivityCompat.checkSelfPermission( context, Manifest.permission.BLUETOOTH_CONNECT ) != 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 (!device.name.isNullOrEmpty()) if (device.name.contentEquals(name)) return true } return false }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)