0

長時間実行すると考えられる Android アプリを開発しています。ある時点で、いくつかの Blutooth デバイス (3.0 と BLE の両方) と通信する必要があるため、必要なときに BlueTooth をオンにし、残りの時間はオフにするという考えです。

私の問題は、BT をオンにすると、デバイスの発見可能性について常に警告が表示され、この警告を削除したい場合に発生します。

解決策を探し回って、試しました:

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivityForResult(discoverableIntent, GlobalConfiguration.REQUEST_DISCOVERABLE);

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Method method;
try {

   method = bluetoothAdapter.getClass().getMethod("setScanMode", int.class, int.class);
   method.invoke(bluetoothAdapter, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, 0);
}
catch(Exception e) {

   e.printStackTrace();
}

どちらも失敗しましたが、BT 状態が ON -> OFF -> ON に切り替わった後、発見可能性に関するダイアログが再び表示されます。

BlueTooth のオン/オフ後も、このアラートを永久に削除する方法はありますか?!

前もって感謝します

4

0 に答える 0