Bluetooth Serial Enable not work

I’m trying to enable Bluetooth if it is not enabled, firstly I check if Bluetooth enabled, if not I try to enable it.
There is my code :

//Check If Bluetooth Enabled Or Not
    this.bluetoothSerial.isEnabled().then(
      function() {
        alert("YES");
    },
      function() {
        alert("NO");
        this.enableBluetooth();
      }
    )

“enableBluetooth” function :

  enableBluetooth(){
    this.bluetoothSerial.enable().then(
      success => {
        alert("Bluetooth is enabled");
      }, failure => {
        alert("The user did *not* enable Bluetooth");
      }
    ); 
  }

I run the application through “Ionic DevApp”.
If I run on chrome browser I get this error in console:

Device: Android.
Used Library: https://ionicframework.com/docs/native/bluetooth-serial

You have to use an android device, if I understand you launch in the browser?

@goku-dev tried through the device and through the browser, from the device does not work for some reason, and from the browser gives me this error.

what version of ionic do you use?

Never type the word “function” inside of one.

1 Like

@rapropos
Continuing the discussion from Bluetooth Serial Enable not work:

now its work :+1:

//Check If Bluetooth Enabled Or Not
this.bluetoothSerial.isEnabled().then(
      () => {
        alert("YES");
    },
      () => {
        alert("NO");
        this.enableBluetooth();
      }
    )

“enableBluetooth” function :

  enableBluetooth(){
    this.bluetoothSerial.enable().then(
      () => {
        alert("Bluetooth is enabled");
      }, () => {
        alert("The user did *not* enable Bluetooth");
      }
    ); 
  }