【问题标题】:Bluetooth Serial - Ionic 2蓝牙串口 - Ionic 2
【发布时间】:2017-02-09 04:51:54
【问题描述】:

我在尝试使用 Android 手机连接蓝牙设备时遇到问题。我已经从 Google Play 测试了一个应用程序并且它可以工作,但是当我从 BluetoothSerial 本机库调用 connect 方法时它不起作用。谁能帮帮我?

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!');
        });

    }

}

问题已解决:我需要在连接之前列出设备

【问题讨论】:

    标签: android cordova typescript bluetooth ionic2


    【解决方案1】:

    我有同样的问题,添加列表没有问题。

    connectDevice(){
    
          /******/
    
              BluetoothSerial.list()
                .then(
                  () => { alert('listed'); },
                  ( err ) => {
                    alert('not listed');
                  } )
    
          /****/
    
              BluetoothSerial.isEnabled()
                .then (
                  () => { alert('enabled'); } ,
                  ( err ) => {
                    BluetoothSerial.showBluetoothSettings()
                      .then(
                        () => { alert('worked') },
                        ( err ) => { alert('notWorking') });
                  } )
    
          /******/
    
    
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-11
      • 2017-11-25
      • 1970-01-01
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      相关资源
      最近更新 更多