I try connect with bluetoohserial from mine android phone in my notebook, but not connect. can u help me… this my code. whats wrong i do!?
import { Component } from '@angular/core';
import { BluetoothSerial } from '@ionic-native/bluetooth-serial';
import { NavController, LoadingController } from 'ionic-angular';
import { AlertController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
infomation: any = [];
spiga: any = [];
constructor(
public alertCtrl: AlertController,
public navCtrl: NavController,
private bluetoothSerial: BluetoothSerial,
public loadingCtrl: LoadingController) { }
ionViewDidLoad() {
this.infomation = { id: "hey it works" };
this.bluetoothSerial.isEnabled().then(() => {
console.log("bluetooth is enabled all G");
}, () => {
console.log("bluetooth is not enabled trying to enable it");
this.bluetoothSerial.enable().then(() => {
console.log("bluetooth got enabled hurray");
}, () => {
console.log("user did not enabled");
})
});
}
connectdevice(devices) {
this.bluetoothSerial.isEnabled().then((res) => {
this.bluetoothSerial.list();
this.bluetoothSerial.connect("00:E1:8C:3F:90:7A");
this.bluetoothSerial.isConnected().then((res) => {
console.log("Device connected with successful " + res);
},
(error) => {
this.showError(error);
console.log("could not find unparied devices " + error);
});
},
(error) => {
this.showError(error);
console.log("could not find unparied devices " + error);
});
}
discover() {
let loading = this.loadingCtrl.create({
spinner: 'bubbles',
content: `Please wait...`,
duration: 10000
});
loading.present();
this.bluetoothSerial.discoverUnpaired().then((device) => {
this.bluetoothSerial.setDeviceDiscoveredListener().subscribe(device => {
this.spiga = [
device
];
console.log(this.spiga);
});
},
(error) => {
this.showError(error);
console.log("could not find unparied devices " + error);
});
}
showDevices(title, id, type, address, name) {
let alert = this.alertCtrl.create({
title: title,
message: id + type + address + name,
buttons: ['OK']
});
alert.present();
}
showError(info) {
let alert = this.alertCtrl.create({
title: "Error",
message: info,
buttons: ['OK']
});
alert.present();
}
}