Android Bluetooth - получение NULL для UUID обнаруженных устройств Bluetooth - PullRequest
0 голосов
/ 20 апреля 2020

Я хочу обмениваться данными между двумя устройствами Bluetooth без сопряжения, и на обоих телефонах будет установлено мое приложение, поэтому я использовал этот метод (https://arxiv.org/ftp/arxiv/papers/1507/1507.00650.pdf). Устройство Bluetooth объявляет список служб, используя UUID. номера.

Так регистрируется услуга =====>

 String uuid = "f2989d52-b3d6-4205-b34d-04f35ea264e5";
 BluetoothAdapter  bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
 BluetoothServerSocket btSocket = bluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord("MYAPP", UUID.fromString(uuid))

Содержание для обратного вызова ===>

    IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    registerReceiver(mReceiver, filter1);
    IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_UUID);
    registerReceiver(mReceiver, filter2);

После этого я звоню

    bluetoothAdapter.startDiscovery();  // to start discovery of devices

Код для обработки намерений ==>

    private  final BroadcastReceiver mReceiver = new
        BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                Log.e("SUNIL","receiver");
                String action = intent.getAction();
                Log.e("SUNIL","receiver action"+action);
                if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    Boolean uuid1 = device.fetchUuidsWithSdp();
                    mDeviceList.add(device);
                    Log.e("SUNIL","device uuid result"+uuid1);
                    Log.e("SUNIL","device"+device.getAddress()+device.getUuids()+device.getBondState());
                } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
                    // discovery has finished, give a call to fetchUuidsWithSdp on first device in list.
                    if (!mDeviceList.isEmpty()) {
                        BluetoothDevice device = mDeviceList.remove(0);
                        boolean result = device.fetchUuidsWithSdp();
                        Log.e("SUNIL", "device uuid result223" + result+"==uuid finished"+device.getUuids());
                    }
                }
                else if (BluetoothDevice.ACTION_UUID.equals(action)) {
                    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    Log.e("SUNIL","device.getUuids()"+device.getUuids());
                    Parcelable[] uuids = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);
                    if(uuids != null) {
                        for (Parcelable ep : uuids) {
                            if (uuids != null) {
                                String uuid = ep.toString();
                                Log.e("SUNIL", "uuid===>" + uuid+"===="+device.getName());
                                             **getting uuid null here**
                            }

                        }
                    }
                }
            }
        };

Пожалуйста, помогите мне, и я новичок в этом API-интерфейсе Bluetooth Я ознакомился с устройствами redmi 6A и redmi 6 PRO

...