bluetoothSerial.setDeviceDiscoveredListener().subscribe() does not return data. What do I do wrong?
global packages:
@ionic/cli-utils : 1.4.0
Cordova CLI : 7.0.1
Ionic CLI : 3.4.0
local packages:
@ionic/app-scripts : 1.3.7
@ionic/cli-plugin-cordova : 1.3.0
@ionic/cli-plugin-ionic-angular : 1.3.0
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.3.0
System:
Node : v6.10.3
OS : Windows 7
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 3.10.10
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BLE } from '@ionic-native/ble';
import { BluetoothSerial } from '@ionic-native/bluetooth-serial';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
listBTDevices: any;
connectedDevice: string;
constructor(public navCtrl: NavController,
private ble: BLE,
private bluetoothSerial: BluetoothSerial) {
this.listBTDevices = [];
this.checkBT();
}
checkBT() {
let me = this;
me.bluetoothSerial.isEnabled().then(
function() {
me.scan();;
me.getListBT();
},
function() {
me.enableBT();
}
);
}
enableBT() {
let me = this;
me.bluetoothSerial.enable().then(
function() {
me.scan();
me.getListBT();
},
function() {
alert("The user did *not* enable Bluetooth");
}
);
}
scan() {
let me = this;
me.bluetoothSerial.discoverUnpaired().then(
devices => {
alert('Devices: ' + JSON.stringify(devices));
devices.forEach(function(device) {
alert(device.name);
})
}, error => {
alert(error);
}
);
me.bluetoothSerial.setDeviceDiscoveredListener().subscribe(
device => {
alert('Found: ' + device.id + '\n' + device.name);
},
error => {
alert('Error scan: ' + JSON.stringify(error));
}
);
}
getListBT() {
let me = this;
this.bluetoothSerial.list().then(
Deviceslist => {
for (let key in Deviceslist) {
me.listBTDevices.push(Deviceslist[key]);
}
}
);
}
}