0
votes

Running the code below, my Galaxy tablet (SCH-I905 - Android 4.0.4) correctly discovers three Bluetooth services on a PC. Running the same code on a Galaxy Nexus - Android 4.2.2) finds only one of the services. Any ideas are appreciated:

private final BroadcastReceiver ServiceReceiver = new BroadcastReceiver()
{
    public void onReceive(Context context, Intent intent) 
    {
        String action = intent.getAction();
        if ( BluetoothDevice.ACTION_UUID.equals(action) )
        {
            BluetoothDevice device = intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
            Parcelable[] uuidExtra = intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");

            for( int i = 0; i < uuidExtra.length; i++ )
            {
               Toast.makeText( this, device.getName() + ": " + uuidExtra[i].toString(), Toast.LENGTH_LONG).show();
            }
        }
    }

};

In the Eclipse debugger, the following array shows three occurrences [00001000-0000-1000-8000-00805f9b34fb, 00001115-0000-1000-8000-00805f9b34fb, 00001202-0000-1000-8000-00805f9b34fb] for the tablet, but only [00001115-0000-1000-8000-00805f9b34fb] for the Nexus. I don't know if it's a version or hardware issue. Thank you, John

One last note - I am using... BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); device.fetchUuidsWithSdp();

1

1 Answers

1
votes

John

This seems to be an Android version issue. I had exactly the same results using an htc desire (Android 2.3) that worked with similar code to yours and a lenovo tablet (Android 4.2.2) that just wont connect no matter what I do. From reading a million posts here is what I have discovered so far:

1) Make sure you cancel the Discovery on your adapter before you try to connect 2) Try using reflection, some people claim this worked for them 3) So try something like this

Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class});
socket = (BluetoothSocket) m.invoke(device, 1);
bluetoothAdapter.cancelDiscovery();
socket.connect();