Connect to a bluetooth device, exception: Service discovery failed
<p>Iam trying to connect my android device with a bluetooth compatible device. I know the mac-address of this device, as you can see in my code below. I also made several <code>Toasts</code> just to verify the steps in the code. It seems that I manage to create <code>tmp = device.createRfcommSocketToServiceRecord(MY_UUID);</code> I assume this because the Toast raises a message saying some bluetooth object address, in this line of code:</p>

<pre><code>String test = tmp.toString(); 
Toast.makeText(getApplicationContext(), "The bluetooth socket: " +test, Toast.LENGTH_LONG).show(); 
</code></pre>

<p>But the code failes semantically when I do a <code>tmp.connect();</code> I am working on API level 15, android 4.0</p>

<p>This i my piece of code</p>

<pre><code>import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;  
import java.util.UUID;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class SimpleConnectAndroidActivity extends Activity {

final static String toast = "IAM HERE"; 

final static String TAG ="SimpleConnect";
UUID MY_UUID;

BluetoothDevice bd;
BluetoothAdapter ba;

Button connectButton;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

    ba = BluetoothAdapter.getDefaultAdapter();

    connectButton = (Button)findViewById(R.id.button1);
    connectButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            boolean b = ba.checkBluetoothAddress("00:1B:DC:0F:EC:7E");
            BluetoothSocket tmp = null; 

            //If valid bluetoothAddress
            if(b) {
                final BluetoothDevice device = ba.getRemoteDevice("00:1B:DC:0F:EC:7E"); //Getting the Verifier Bluetooth 

                //Trying to create a RFCOMM socket to the device
                try {
                    tmp = device.createRfcommSocketToServiceRecord(MY_UUID);

                } catch (IOException e) {

                }

                try {
                    tmp.connect();
                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "No connection was made! Exception: " + e.getMessage(), Toast.LENGTH_LONG).show();
                } 
                //Print out the sockets name
                String test = tmp.toString(); 
                Toast.makeText(getApplicationContext(), "The bluetooth socket: " +test, Toast.LENGTH_LONG).show(); 
            }


            else {
                    Toast.makeText(getApplicationContext(), "FALSE, No bluetooth device with this address", Toast.LENGTH_LONG).show();
                }
            }   
    });  
}
</code></pre>

<p>}</p>

<p>I am aware of that this should be done in a separate thread, and yes, I read the Bluetooth Chat example provided by Google. </p>

<p>Can someone help me out? </p>

<p><strong>EDIT</strong></p>

<p>This is the only thing I got from LogCat:</p>

<pre><code>07-06 10:10:22.085: V/BluetoothSocket.cpp(14019): ...fd 63 created (RFCOMM, lm = 26)
</code></pre>

<p><strong>EDIT 2</strong></p>

<p>Ok, now got a new error, but its a better error. When i press the connect button, the phone asks for the pin code for pair the devices, but its already paired! After I paired it for the second time, the error says: Connection refused and another exception says, timeout. </p>
