簡體   English   中英

檢測藍牙發現已開啟?

[英]detect Bluetooth Discovery is on?

我想檢測藍牙發現是否開啟? 可能嗎 ?

Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 1);
startActivity(discoverableIntent);

上面的代碼是關於啟用/禁用藍牙光盤狀態,但不顯示藍牙迪斯科狀態

要確定藍牙設備是否可發現(處於查詢掃描狀態),請使用getScanMode() ,如下所示:

BluetoothAdapter bAdapter = BluetoothAdapter.getDefaultAdapter();
if(bAdapter.getScanMode() == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
    // device is discoverable & connectable
} else {
    // device is not discoverable & connectable
}

getScanMode()的文檔

int android.bluetooth.BluetoothAdapter.getScanMode()

獲取本地藍牙適配器的當前藍牙掃描模式。

藍牙掃描模式確定本地適配器是否可連接和/或可從遠程藍牙設備發現。

bluetoothAdapter.isDiscovering();

應該做你想要的。 您可以通過以下方式獲取默認的BluetoothAdapter對象:

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

您可以在Android BluetoothAdapter文檔中了解這兩種方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM