Unable to pair Remote bluetooth device with android phone
<p>I use the bluetooth chat application for my refrence.In BluetoothchatService.java i change AcceptThread and ConnectThread , which is as follows ..........</p>

<p>private class AcceptThread extends Thread {
        private final BluetoothServerSocket mmServerSocket;</p>

<pre><code>    public AcceptThread() {
        BluetoothServerSocket tmp = null;

        // Create a new listening server socket
        try {
            tmp = mAdapter
                    .listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
        } catch (IOException e) {
            Log.e(TAG, "listen() failed", e);
        }
        mmServerSocket = tmp;
    }

    public void run() {
        if (D)
            Log.d(TAG, "BEGIN mAcceptThread" + this);
        setName("AcceptThread");
        BluetoothSocket socket = null;

        // Listen to the server socket if we're not connected
        while (mState != STATE_CONNECTED) {
            try {
                // This is a blocking call and will only return on a
                // successful connection or an exception
                socket = mmServerSocket.accept();
            } catch (IOException e) {
                Log.e(TAG, "accept() failed", e);
                break;
            }

            // If a connection was accepted
            if (socket != null) {
                synchronized (BluetoothChatService.this) {
                    switch (mState) {
                    case STATE_LISTEN:
                    case STATE_CONNECTING:
                        // Situation normal. Start the connected thread.
                        connected(socket, socket.getRemoteDevice());
                        break;
                    case STATE_NONE:
                    case STATE_CONNECTED:
                        // Either not ready or already connected. Terminate
                        // new socket.
                        try {
                            socket.close();
                        } catch (IOException e) {
                            Log.e(TAG, "Could not close unwanted socket", e);
                        }
                        break;
                    }
                }
            }
        }
        if (D)
            Log.i(TAG, "END mAcceptThread");
    }

    public void cancel() {
        if (D)
            Log.d(TAG, "cancel " + this);
        try {
            mmServerSocket.close();
        } catch (IOException e) {
            Log.e(TAG, "close() of server failed", e);
        }
    }
}

/**
 * This thread runs while attempting to make an outgoing connection with a
 * device. It runs straight through; the connection either succeeds or
 * fails.
 */
private class ConnectThread extends Thread {
    private final BluetoothSocket mmSocket;
    private final BluetoothDevice mmDevice;

    public ConnectThread(BluetoothDevice device) {
        mmDevice = device;
        BluetoothSocket tmp = null;

        // Get a BluetoothSocket for a connection with the
        // given BluetoothDevice
        try {
            //tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
            Method m = device.getClass().getMethod("createRfcommSocket",
                    new Class[] { int.class });
            tmp = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));


        } catch (Exception e) {
            Log.e(TAG, "create() failed", e);
        }
        mmSocket = tmp;
    }

    public void run() {
        Log.i(TAG, "BEGIN mConnectThread");
        setName("ConnectThread");

        // Always cancel discovery because it will slow down a connection
        mAdapter.cancelDiscovery();

        // Make a connection to the BluetoothSocket
        try {
            // This is a blocking call and will only return on a
            // successful connection or an exception
            mmSocket.connect();
        } catch (IOException e) {
            connectionFailed();
            // Close the socket
            try {
                mmSocket.close();
            } catch (IOException e2) {
                Log.e(TAG,
                        "unable to close() socket during connection failure",
                        e2);
            }
            // Start the service over to restart listening mode
            BluetoothChatService.this.start();
            return;
        }

        // Reset the ConnectThread because we're done
        synchronized (BluetoothChatService.this) {
            mConnectThread = null;
        }

        // Start the connected thread
        connected(mmSocket, mmDevice);
    }

    public void cancel() {
        try {
            mmSocket.close();
        } catch (IOException e) {
            Log.e(TAG, "close() of connect socket failed", e);
        }
    }
}
</code></pre>

<p>When i am pairing with remote bluetooth device it getting paired but suddenly it gives exception and got disconnect..... </p>

<p>04-05 18:15:27.696: ERROR/BluetoothChatService(19342): accept() failed
04-05 18:15:27.696: ERROR/BluetoothChatService(19342): java.io.IOException: Software caused connection abort
04-05 18:15:27.696: ERROR/BluetoothChatService(19342):     at android.bluetooth.BluetoothSocket.acceptNative(Native Method)
04-05 18:15:27.696: ERROR/BluetoothChatService(19342):     at android.bluetooth.BluetoothSocket.accept(BluetoothSocket.java:287)
04-05 18:15:27.696: ERROR/BluetoothChatService(19342):     at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:105)
04-05 18:15:27.696: ERROR/BluetoothChatService(19342):     at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:91)
04-05 18:15:27.696: ERROR/BluetoothChatService(19342):     at com.example.android.BluetoothChat.BluetoothChatService$AcceptThread.run(BluetoothChatService.java:317)</p>

<p>Hope my Question is cleared... 
please reply as soon as possible...</p>

<p>Thankssssssssssss</p>
