离子低能耗蓝牙设备未列出

时间:2019-02-09 04:03:59

标签: ionic-framework connection bluetooth-lowenergy

我正在尝试构建一个可在Android上运行的Ionic应用程序原型,我只想在其中查看通过低功耗蓝牙连接的设备列表。我使用的物理设备是智能手表Ticwatch E,它通过蓝牙v4.1 / BLE连接到我的手机。当我运行该应用程序时,它表明有o个设备通过Bluetooth v4.1 / BLE连接。下面是代码。有人可以帮我吗?

(我是打字稿和javascript的新手,偶尔写几行代码,所以也可能会出现代码错误)

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';


import { BluetoothLE, DeviceInfo } from '@ionic-native/bluetooth-le';
import { Platform } from 'ionic-angular';
import { Toast } from '@ionic-native/toast';

@Component({
 selector: 'page-home',
 templateUrl: 'home.html'
})
export class HomePage {

 foundDevices = [];

 constructor(public navCtrl: NavController, public bluetoothle: BluetoothLE, public plt: Platform,
   private toast: Toast
 ) {
   let connectedObj: DeviceInfo[] = [];

   this.plt.ready().then((readySource) => {

     bluetoothle.requestPermission().then(dataTemp => {
       console.log('Platform ready from', readySource);

       this.toast.show("Platform ready from", '5000', 'center').subscribe(
         toast => {
           console.log(toast);
         }
       );
        this.bluetoothle.initialize().then(ble => {

         console.log('ble', ble.status) // logs 'enabled'
          this.toast.show(ble.status, '15000', 'center').subscribe(
           toast => {
             console.log(toast);
           });


         this.bluetoothle.retrieveConnected().then(connectedObj => {
            this.toast.show("Length: " + connectedObj.devices.length, '25000', 'center').subscribe(
             toast => {
               console.log(toast);
             });

          });

        });
     });

   });

 }

0 个答案:

没有答案