我想编辑一个通过蓝牙发送信息的程序,即使我在设备上尝试,我的源代码也在这里,它仍然给我"无法启用蓝牙"。
import { Injectable } from '@angular/core';
import { BluetoothSerial } from 'ionic-native';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
/*
Generated class for the BluetoothTracker provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class BluetoothTracker {
constructor(public http: Http) {
console.log('Hello BluetoothTracker Provider');
}
startConnection(){
BluetoothSerial.isEnabled()
.then(
( succes ) => { alert( "bluetooth enabled." ); },
( err ) => {
BluetoothSerial.enable()
.then(
( succes ) => { alert( "enabling bluetooth worked. " ); },
( err ) => { alert( "can't enable bluetooth. " ); }
);
}
);
}
}
这是解决方案,我必须使用函数bluetoothserial.list(),从我想发送信息的地方选择设备的蓝牙接口。
/** Select bluetooth interface from where i should be connected **/
BluetoothSerial.list().then(
( devices ) => { JSON.stringify( devices ); },
( err ) => { alert( " cant list devices" + err ); }
);