0
現在、私はcordova.plugins.diagnosticを使用して、Bluetoothが現在オンかオフかをチェックしています。ブルートゥースがオフの場合、ユーザにそれをオンにするよう要求するプロンプトが表示され、「継続ボタン」が無効になります。それが既にオンになっている場合、どうすればそれが既にオンであるかを検出し、継続ボタンを有効にすることができます。Ionic - ブルートゥースの状態変更を確認する方法
以下はBluetoothが有効/無効で検出する方法コードである:
cordova.plugins.diagnostic.isBluetoothEnabled(function(enabled){
console.log("Bluetooth is " + (enabled ? "enabled" : "disabled"));
}, function(error){
console.error("The following error occurred: "+error);
});
そして、これはBluetoothの状態に対して行われた変更を確認する方法コードである:
$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;
}
});
})
ただし、オフからオンまたはオフからテストすると、アラートが表示されません。ハンドラがコールバックしていないようです。
感謝を聞いて、あなたは "ボタンを続行" イベントで 'cordova.plugins.diagnostic.setBluetoothState'を置くことによって意味ですか?だから私はそのボタンを作ることができますブルートゥースがオンの後に有効になりますか? –
「ボタン無効」=「ボタン無効」=「!bluetoothIsEnabled」オンタップ=「yourFunction($イベント)」>「 –
はい、私はそれを理解していますが、 bluetoothIsEnabledがfalseの場合は有効になります。なぜなら、私のシナリオからは、ブルートゥースが消える前に言及しているからです。ユーザがブルートゥースを有効にした後、この 'cordova.plugins.diagnostic.isBluetoothEnabled'はコールバックではなく、値' bluetoothIsEnabled'をtrueに変更します。 –