ARTICLE AD BOX
I built a Java app where I implemented bluetooth functionality. Using the documentation I managed to discover devices and pair with them. I managed to get the whole device info (address, name), but it fails when I want to establish communication with the module.
In the ConnectThread constructor:
if (ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) { try { tmp = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); } catch (IOException e) { Log.e(TAG, "Socket's create() method failed", e); } } else { Log.e(TAG, "Missing BLUETOOTH_CONNECT permission"); } targetSocket = tmp;In the ConnectThread method run():
bluetoothAdapter.cancelDiscovery(); try { targetSocket.connect(); Log.i(TAG, "Connection successful!"); } catch (IOException e) { Log.d(TAG, Log.getStackTraceString(e)); Log.e(TAG, "Could not connect; closing socket", e); try { targetSocket.close(); } catch (IOException e2) { Log.e(TAG, "Could not close the client socket", e2); } }In the MainActivity, when I choose a device from the paired devices list:
ConnectThread connectThread = new ConnectThread(device, mBluetoothManager, MainActivity.this); connectThread.start();**
What I have in my LOGCAT**
Using the Serial Bluetooth Terminal from google play I managed to connect to my module and send data so I figure that the problem is on my end but I can't find any information about why this happens.
