Ionic - How To Check Bluetooth State Change
<p>Currently I'm using <a href="https://www.npmjs.com/package/cordova.plugins.diagnostic" rel="nofollow">cordova.plugins.diagnostic</a> to check whether the Bluetooth is currently On or Off. If the Bluetooth is Off then a prompt asking user to turn it On and 'Continue Button' is disabled. After it already On, how can I detect it is already On and make the Continue Button enable. </p>

<p>Below is a code how to detect Bluetooth is enable/disable:</p>

<pre><code>cordova.plugins.diagnostic.isBluetoothEnabled(function(enabled){
    console.log("Bluetooth is " + (enabled ? "enabled" : "disabled"));
}, function(error){
    console.error("The following error occurred: "+error);
});
</code></pre>

<p>Then, this is the code how to check the changes made for bluetooth state:</p>

<pre><code>$ionicPlatform.ready(function() {
     cordova.plugins.diagnostic.registerBluetoothStateChangeHandler(function(state ){

    if(state === cordova.plugins.diagnostic.bluetoothState.POWERED_ON){
        alert("Bluetooth is able to connect");
        $scope.bluetoothIsEnabled = true;
    }

    else if(state === cordova.plugins.diagnostic.bluetoothState.POWERED_OFF){
       alert("Bluetooth is Off");
       $scope.bluetoothIsEnabled = false;
   }
});
</code></pre>

<p>})</p>

<p>But, if I test from Off to On or On to Off, there is no any alert appear. Seems like the handler is not call back.</p>