0

I need to take measurements from an A&D Medical UA-767PBT (without the ending "C") to a simple android app. The UA-767PBT uses SDP and SPP to communicate with an access point (my android tablet). I have the service name, cod filter and pin. I've used the BluetoothChat example like a starting point, i've modified the "listenUsingRfcommWithServiceRecord" using the right service name, SPP UUID and set a pin with refelection, but the app still saying "Unable to connect to the device". I've read here Can't accept an incoming bluetooth connection unless device is discoverable something about a port problem, but i don't know how to do these things.

Someone was able to connect to this device and give me some hint/example please?

thanks

P.S. I've just connected easily to an A&D UA-767PBT-C.

P.P.S. and sorry for my english :D

Community
  • 1
  • 1
user261591
  • 11
  • 1
  • 6

1 Answers1

0

You need to be in discoverable mode the first time you try to connect with the UA-767PBT. After enabling bluetooth, insert this code in your onCreate():

Intent discoverableIntent = new  
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivity(discoverableIntent);

This will put your device in discoverable mode with no time limits. You can also do it directly in your device settings: Settings->Bluetooth->(menu in top-right)Visibility timeout->Never time out

After that, you need to create a BluetoothServerSocket using "listenUsingRfcommWithServiceRecord" with the right parameters as you said, and then accept the connection like this:

 BluetoothSocket socket = null;
 socket = yourServerSocket.accept();

I do this in a separate thread. Hope this will help you!

  • Hi, For me it doesn't work in that way. It works only the first time you connect with the device, all the other times it doesn't work. I've noticed that probably it's some problem with the dedicated port. Are you sure that you have the PBT and not the PBT-C? – user261591 Sep 03 '14 at 12:46
  • Yes, pretty sure :) I found out that the problem with multiple connections was that I used to close the serverSocket once connected. Actually, that device seems to constantly connect and disconnect... so I just kept the serverSocket opened and I didn't have problems anymore. To explain better, referring to developer site, do not call the " mmServerSocket.close();" Try this way and let me know! – user3726420 Sep 04 '14 at 14:31
  • Hi, thanks for the answers! the problem is that the device doesn't connect with the server :D I open the server with the listenusingrfcomm etc. and the device connects with the server (not always...). But if I restart the application and open the same server with the same attributes, the device can't establish a connection anymore! I close the server socket only at the end of all, after i take the measurement (IF i take a measurement XD) – user261591 Sep 05 '14 at 07:35