Ok, I will try one more time.
I have a device sdptool in ubuntu the following is stated from my device:
# sdptool browse C0:1B:DC:1F:E2:F1 Browsing C0:1B:DC:1F:E2:F1 ... Service Name: OBEX Object Push Service RecHandle: 0x10000 Service Class ID List: "OBEX Object Push" (0x1105) Protocol Descriptor List: "L2CAP" (0x0100) "RFCOMM" (0x0003) Channel: 9 "OBEX" (0x0008) Profile Descriptor List: "OBEX Object Push" (0x1105) Version: 0x0100 As you can se the device does support the RFCOMM protocol, and OBEX for file transfer. I have a simple code for my android app which tries to connect to this device over a insecure RFCOMM channel, just for no user interaction. I want to connect to this device, so Iam using the device mac-address for connection, and the socket is ready, logcat says so.
But I only get the error:
Connection refused Have in mind that the mac-address in the java code is different from the following listed above.
So here is my 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 = new UUID(0x0100 , 0x1000); // MY_UUID = UUID.fromString("8e1f0cf7-508f-4875-b62c-fbb67fd34812"); connectButton = (Button)findViewById(R.id.button1); connectButton.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { BluetoothSocket tmp = null; BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("00:1B:DC:0F:EC:7E"); Method m = null; try { m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class}); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { tmp = (BluetoothSocket) m.invoke(device, 1); } catch (IllegalArgumentException e) { Toast.makeText(getApplicationContext(), "Exception: " + e.getMessage(), Toast.LENGTH_LONG).show(); } catch (IllegalAccessException e) { Toast.makeText(getApplicationContext(), "Exception: " + e.getMessage(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } catch (InvocationTargetException e) { Toast.makeText(getApplicationContext(), "Exception: " + e.getMessage(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } try { tmp.connect(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Exception: " + e.getMessage(), Toast.LENGTH_LONG).show(); try { tmp.close(); } catch (IOException e1) { Toast.makeText(getApplicationContext(), "Socket closed!" + e.getMessage(), Toast.LENGTH_LONG).show(); } } boolean con = tmp.isConnected(); if(con) Toast.makeText(getApplicationContext(), "Connection was made!", Toast.LENGTH_LONG).show(); else Toast.makeText(getApplicationContext(), "Connection was not made!", Toast.LENGTH_LONG).show(); } }); } }
I've read several places that it should work by un-pairing and pair again, but this doesn't solve my problem.