Android Bluetooth does not show pairing dialog

I am trying to pair my HTC myTouch 3G with a Bluetooth device that will transfer data via SPP to the phone. I looked through the chat examples and found that they were missing what I needed because I needed high data rates, and the chat example blocked the user interface stream. But this suggests that my main problem is that when I try to connect a device that is not currently paired, the Bluetooth API says that it will automatically open a dialog box if the device requires a pairing code. It never happens. How can I make sure this is so? Here is my code ...

            BluetoothSocket btSocket;
            String macAddress = data.getStringExtra("mac");
            Log.d(TAG, "Found Device " + macAddress);

            // Get the Bluetooth adapter on the device
            BluetoothAdapter bta = ((MyApplication)this.getApplication()).getBtState();
            BluetoothDevice btDevice = bta.getRemoteDevice(macAddress);
            BluetoothSocket tmp = null;
            try {
                tmp = btDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (tmp != null) {
                btSocket = tmp;
                bta.cancelDiscovery();

                try {
                    btSocket.connect();
                } catch (IOException e) {
                    try {
                        Log.e(TAG, "------------- Close IOException");
                        btSocket.close();
                    } catch (IOException e2) {
                        Log.e(TAG, "unable to close() socket during connection failure", e2);
                    }
                }
            }   

Here is the error I am getting too:

ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Adapter:DeviceCreated from /org/bluez/14284/hci0
ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/14284/hci0
ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/14284/hci0/dev_00_02_5B_00_A5_0B
ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/14284/hci0/dev_00_02_5B_00_A5_0B
DEBUG/BluetoothService(149): updateDeviceServiceChannelCache(00:02:5B:00:A5:0B)
DEBUG/BluetoothService(149):     uuid(application): 00001101-0000-1000-8000-00805f9b34fb 1
DEBUG/BluetoothService(149): Making callback for 00001101-0000-1000-8000-00805f9b34fb with result 1
VERBOSE/BluetoothEventRedirector(13691): Received android.bleutooth.device.action.UUID
ERROR/MainApp(14272): ------------- Close IOException
ERROR/BluetoothService.cpp(149): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/14284/hci0/dev_00_02_5B_00_A5_0B
VERBOSE/BluetoothEventRedirector(13691): Received android.bleutooth.device.action.UUID

, , , , , Bluetooth , . , Bluetooth myTouch 2,1, , , 1,2

+5
2

bluetooth , BT

+1

Bluetooth ( SPP). , , - .

Nexus S Bluetooth- ( listenUsingRfcommWithServiceRecord), . SonyEricsson Xperia ARC SonyEricsson X10 Mini Pro. HTC Wildfire (2.2.1), HTC Legend (2.2) Samsung Galaxy S (2.2.1).

, , , Bluetooth 1.2 , , .

, Wildfire, , Legend Galaxy S. . , Bluetooth, , . , !

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

Method m = mAdapter.getClass().getMethod("createRfcommSocketToServiceRecord", new Class[] { UUID.class });
tmpSocket = (BluetoothServerSocket) m.invoke(mAdapter, new Object[] { MY_UUID });
+4

All Articles