Hi, I currently run android 1.5 on a HTC magic. I'm trying to communicate from my phone to a bluetooth device that supports SPP. I can't seem to be able to connect to the device. I have tryed two ways to connect: 1- via the official 2.0 API using the backport-android to make it work on android 1.5 2- via the unofficial bluetooth api 0.3
Both method give me an error around the same connection process. With API 2.0, I can discover devices and pair with them. Then i create a socket which seems to work, but when I use the .connect() method, I get this error in CatLog: IOException Unable to start Service Discovery. This is related to doSdp() in public class BluetoothSocket. Searching the web, it seems this error is related to a wrong UUID ... but I am using the SPP UUID properly. So, I thought the problem could be backport android, so I tried with the unofficial API from Gerdavax ( http://code.google.com/p/android-bluetooth/ ) To connect to a device with this API you first create a socket, then you connect using the .openSocket( port number) method. The weird thing is, if I try with a new port, it connects, if I try a second time, it wont work, unless I change the port. I get a similar related error of SDP. Here is my code for API 2.0, but im pretty sure its ok. public class RegulVoile extends Activity { private BluetoothAdapter adapteurGen= null; private BluetoothDevice moduleDistant = null; public String adressTrouver = null; private BluetoothSocket socketBt = null; private static final UUID MON_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //final TextView modeText= (TextView)this.findViewById(R.id.txt_state); //final TextView infoText= (TextView)this.findViewById(R.id.txt_name); Button connectionBt = (Button)this.findViewById(R.id.btn_connexion); adapteurGen = BluetoothAdapter.getDefaultAdapter(); connectionBt.setOnClickListener(new OnClickListener(){ public void onClick(View v){ //make SURE there is not a discovery going on. adapteurGen.cancelDiscovery(); moduleDistant = adapteurGen.getRemoteDevice("00:1D: 43:00:D1:0D"); try{ socketBt = moduleDistant.createRfcommSocketToServiceRecord(MON_UUID); } catch (IOException e) { } //try the connect try { socketBt.connect(); } catch (IOException e) { try { e.printStackTrace(); socketBt.close(); } catch (IOException e2) { } } } }); } @Override protected void onStop() { try { socketBt.close(); } catch (IOException e1) { e1.printStackTrace(); } super.onStop(); } @Override protected void onDestroy() { try { socketBt.close(); } catch (IOException e1) { e1.printStackTrace(); } super.onDestroy(); } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en