ブラウザがBluetoothデバイスを検出できないため、実際のデバイスでアプリを実行しようとしているため、動作していないと思います。次に、USBデバッグを介してchrome:// inspectを使用してログを表示します。
私はあなたのコードとその作業を編集しました。これだよ。検出されなかったデバイスをペアにして表示します。
import {Component} from '@angular/core';
import {AlertController, NavController} from 'ionic-angular';
import {BluetoothSerial} from '@ionic-native/bluetooth-serial';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public deviceList:any;
constructor(public navCtrl: NavController,
private alertCtrl:AlertController,
private bluetoothSerial: BluetoothSerial) {
this.getAllBluetoothDevices();
}
// put BluetoothSerial inside a function, can't be called different
getAllBluetoothDevices() {
// async so keep everything in this method
this.bluetoothSerial.isEnabled().then(data => {
if(data){
this.bluetoothSerial.list().then(allDevices=> {
// set the list to returned value
if(allDevices.length > 0){
this.deviceList=allDevices;
}else{
let alert = this.alertCtrl.create({
title: 'Bluetooth',
subTitle: 'No devices found.',
buttons: ['Dismiss']
});
alert.present();
}
});
}
}).catch(err=>{
let alert = this.alertCtrl.create({
title: 'Bluetooth',
subTitle: 'Check your bluetooth connection.',
buttons: ['Dismiss']
});
alert.present();
});
}
}
[編集] ingであなたのpackage.jsonを追加できますか? –
私は今質問を更新します –