无法使用Cordova蓝牙插件过滤蓝牙结果

时间:2020-07-07 12:33:54

标签: javascript angular cordova bluetooth-lowenergy cordova-plugins

我有以下代码来初始化角度为9的蓝牙和外围设备

(window as any).bluetoothle.initialize(function initializeResult(result) {
      console.log(result);

    }, params);
    (window as any).bluetoothle.initializePeripheral(
      function initializeResult(result) {
        
        console.log(result);
      },
      function error(result) {
        console.log(result);
      },
      {
        request: true,
        restoreKey: 'bluetoothleplugin'
      }
    );

我正在使用以下代码创建新的服务和广告:-

     let servicee;
    (window as any).bluetoothle.addService(
      function success(result) {
        
        console.log(result);
        servicee = result.service;
        (window as any).bluetoothle.startAdvertising(
          function success(result) {
           
            console.log(result);
          },
          function error(result) {
            
            console.log(result);
          }, {
            services: ['1234'], // iOS
            service: '1234', // Android
            name: 'Hello World',
            timeout: 180000
          }
        );
      },
      function error(result) {
        
        console.log(result);
      }, {
        service: '1234',
        characteristics: [
          {
            uuid: '1234',
            permissions: {
              read: true,
              write: true,

            },
            properties : {
              read: true,
              writeWithoutResponse: true,
              write: true,
              notify: true,
              indicate: true,

            }
          }
        ]
      }
    );

,然后使用以下代码进行扫描:-

(window as any).bluetoothle.startScan(function startScanSuccessCallback(result) {
      console.log('printing result');
      console.log(result);
      console.log((window as any).bluetoothle.encodedStringToBytes(result.advertisement));
    }, function startScanErrorCallback(err) {
      console.log('printing err');
      console.log(err);
    }, {serviceUuids: ['1234', servicee]});//servicee stored above while creating a service

但是我无法提交仅具有我创建的服务('1234')的设备,相反,我想获得唯一具有我的服务的设备。 通过在两个设备上注册服务来在两个设备上运行该应用程序来实现,但是在搜索时却得到了所有设备。 注意:-我的设备都是Android智能手机

0 个答案:

没有答案
相关问题