davidhubbard / gobbed

Free Software for connecting to your vehicle's data buses
Other
3 stars 0 forks source link

Expose Bluetooth SDP API on Android to make it more in line with the Chrome Bluetooth API #7

Open davidhubbard opened 8 years ago

davidhubbard commented 8 years ago

Here is some code I wrote attempting to do SDP on devices that have not been paired with (result is that getUuids() returns null because the device's UUIDs are not in the Android Bluetooth cache)

        filter = new IntentFilter(BluetoothDevice.ACTION_UUID);
        gobbedWebView.parentActivity.registerReceiver(mReceiver, filter);

                // Must wait for the discovery method to finish before calling another method.
                // (Methods cannot be run in parallel.)
                // http://stackoverflow.com/questions/14812326/android-bluetooth-get-uuids-of-discovered-devices

            } else if (BluetoothDevice.ACTION_UUID.equals(action)) {
                /*if (Build.VERSION.SDK_INT >= 15 && dev.getUuids() == null) { // API 15: Icecream MR1
                    // If you have never attempted to pair or connect with the device, UUIDs will
                    // not be cached.
                    if (!dev.fetchUuidsWithSdp()) {
                        Log.w(TAG, "fetchUuidsWithSdp() returned false. Sanity check failed?");
                    }
                }*/
                Log.w(TAG, "ACTION_UUID:");
                BluetoothDevice dev = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                Log.w(TAG, "ACTION_UUID: " + dev.getAddress());
                boolean isNewDev = mDeviceList.put(dev.getAddress(), dev) == null;
                gobbedWebView.runJsCallbacks("bluetooth", isNewDev ? "addCb" : "devCb",
                        findDevIndex(dev));