• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps BluetoothDevice.createrfcommsockettoservicerecord is Null

BrainTrance

Lurker
Jun 6, 2019
1
1
I have successfully recognised the bluetooth device (HC-05), I got its name, MAC address, and bond state, but when I'm trying to create a client socket in order to initiate a bluetooth connection with it I got a null socket.

This is my code:

//initializing bluetooth adapter
val bluetoothAdapter: BluetoothAdapter? = BluetoothAdapter.getDefaultAdapter()
if (bluetoothAdapter?.isEnabled == false) {
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
}

//creating a list of PAIRED DEVICES
val pairedDevices: Set<BluetoothDevice>? = bluetoothAdapter?.bondedDevices

//define a BluetoothDevice (the first on the list)
pairedDevices?.forEach { device ->
val deviceName = device.name
val deviceHardwareAddress = device.address // MAC address
val arduino: BluetoothDevice = pairedDevices.first()

Then i try:

val arduinoSocket = arduino?.createRfcommSocketToServiceRecord(uuid)

which is null.

The UUID is:
private val uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")

Any insights? Thanks
 
  • Like
Reactions: lillycarrie82

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones