为什么在Android 4.3上没有提供蓝牙UUID?

时间:2013-10-25 04:30:19

标签: android android-intent android-bluetooth

我有一些代码可以监听蓝牙发现事件,列出已发现的设备及其UUID。

现在,这段代码在Androids 2.3到4.1上完美运行。但是,在4.3(没试过4.2),突然之间,我再也看不到任何地方的UUID了。唯一的区别似乎只是缺少任何UUID信息。

这是广播接收者代码:

    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        Log.d(TAG, "BTReceiver got action " + action);

        if (BluetoothDevice.ACTION_FOUND.equals(action)) {

            BluetoothDevice device =
                    intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            Parcelable[] extraUIIDs = device.getUuids();

            if (extraUIIDs == null) {
                device.fetchUuidsWithSdp();
            }
        }

        if (BluetoothDevice.ACTION_UUID.equals(action)) {

            BluetoothDevice device =
                    intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            Parcelable[] pUUIDs = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);

            if (pUUIDs == null) {
                pUUIDs = device.getUuids();
                Log.d(TAG, "No UUIDs in intent, trying from device : "+pUUIDs);
            }

        }

    }

在较旧的Androids中,我会看到设备对象中的UUID,或者与UUID动作一起收到。在4.3中,我仍然收到UUID操作,但是intent和设备对象中的UUID数组都是null

同样,唯一的区别是Android版本(和设备),但是只要它们低于4.2,它就可以在我可以得到的所有机器上保持一致。

0 个答案:

没有答案