Android で BLE の状態(有効・無効)をチェック

Android で Bluetooth との通信を行う前に、Bluetooth が有効にされているかをチェックする。

BluetoothManager bluetoothManager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
if (bluetoothAdapter == null) {
    // TODO: 端末がBLEに対応していない時の処理
} else if (!bluetoothAdapter.isEnabled()) {
    // TODO: 端末でBLEが有効にされていない時の処理
}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA