This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can't connect Android to nRF52832

I'm trying to create a connection between Android 6.0 and nRF52832. I created a service, like in tutorial, added it's uuid to adv packet (I seeit in nRF Connection). I can connect to it using nRF Connection, but I can't do it using my android app.

In android app I use BroadcastReceiver and if I find device with necessary name I do folowing:

mUUID = UUID.fromString("663dabcd-f115-4534-8f23-da6c1aab40d3");
connectThr = new ConnectThread(osankaDevice);
connectThr.start();

That's a uuid from my service. And I can see it in adv packet.

ConnectThread is folowing:

private class ConnectThread extends Thread {
    private BluetoothSocket mSocket;
    private BluetoothDevice mDevice;

    public ConnectThread(BluetoothDevice device) {
        BluetoothSocket tmp = null;
        try {
            tmp = device.createRfcommSocketToServiceRecord(mUUID);
        } catch (IOException e) {
            Log.d("CONNECTTHREAD","Could not create RFCOMM socket:" + e.toString());
        }
        mSocket = tmp;
        btSocket = mSocket;
        mDevice = device;
        btDevice = mDevice;
    }

    public void run() {
        BA.cancelDiscovery();
        String exitException = "No";

        try {
            mSocket.connect();
            exitException = "No";
        } catch (IOException e) {
            Log.d("CONNECTTHREAD","Could not connect: " + e.toString());
            exitException = "Yes";
        }

        if(exitException.equals("Yes")){
            //findbtPopupW.dismiss();
            try {
                mSocket.close();
            } catch (IOException exception){
                Log.d("CONNECTTHREAD","Could not close connection:" + exception.toString());
            }
        }
    }

    public void cancel() {
        try {
            mSocket.close();
        } catch (IOException e) {
            Log.d("CONNECTTHREAD","Could not close connection:" + e.toString());
        }
    }
}
Related