简体   繁体   English

检测蓝牙发现已开启?

[英]detect Bluetooth Discovery is on?

I want to detect whether Bluetooth discovery is on or no ? 我想检测蓝牙发现是否开启? is it possible ? 可能吗 ?

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

above code is about enabling /diabling blutooth disc state , but do not show bluetooth disco state 上面的代码是关于启用/禁用蓝牙光盘状态,但不显示蓝牙迪斯科状态

To find out if the bluetooth device is discoverable (in the inquiry scan state), use getScanMode() , as in the following: 要确定蓝牙设备是否可发现(处于查询扫描状态),请使用getScanMode() ,如下所示:

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

Documentation of getScanMode() : getScanMode()的文档

int android.bluetooth.BluetoothAdapter.getScanMode() int android.bluetooth.BluetoothAdapter.getScanMode()

Get the current Bluetooth scan mode of the local Bluetooth adapter. 获取本地蓝牙适配器的当前蓝牙扫描模式。

The Bluetooth scan mode determines if the local adapter is connectable and/or discoverable from remote Bluetooth devices. 蓝牙扫描模式确定本地适配器是否可连接和/或可从远程蓝牙设备发现。

bluetoothAdapter.isDiscovering();

should do what you're looking for. 应该做你想要的。 You can get the default BluetoothAdapter object via: 您可以通过以下方式获取默认的BluetoothAdapter对象:

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

You can read about both of those methods in the Android BluetoothAdapter doc . 您可以在Android BluetoothAdapter文档中了解这两种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM