2016-09-30 109 views
2

我在嘗試使用Android手機在藍牙設備中進行連接時遇到問題。我已經從Google Play測試了一個應用程序,它可以正常工作,但是當我從BluetoothSerial本機庫調用connect方法時,它不起作用。任何人都可以幫助我嗎?Bluetooth Serial - Ionic 2

import { Component } from '@angular/core'; 

import { NavController } from 'ionic-angular'; 
import { BluetoothSerial } from 'ionic-native'; 

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

    constructor(public navCtrl: NavController) { 

    } 

    connect() { 

     BluetoothSerial.isEnabled().then(res => { 

      BluetoothSerial.connect('20:14:02:18:17:84'); 
      BluetoothSerial.isConnected().then(res => { 
       console.log(res); 
      }).catch(res => { 
       console.log('Fail2!'); 
       console.log(res); 
      }); 

     }).catch(res => { 
      console.log('Fail!'); 
     }); 

    } 

} 

問題就迎刃而解了:我需要列出這些設備我連接

回答

0

之前我有同樣的問題,並加入列表不給的問題。

connectDevice(){ 

     /******/ 

      BluetoothSerial.list() 
      .then(
      () => { alert('listed'); }, 
       (err) => { 
       alert('not listed'); 
       }) 

     /****/ 

      BluetoothSerial.isEnabled() 
      .then (
      () => { alert('enabled'); } , 
       (err) => { 
       BluetoothSerial.showBluetoothSettings() 
        .then(
        () => { alert('worked') }, 
        (err) => { alert('notWorking') }); 
       }) 

     /******/ 


    }