gpt4 book ai didi

android - 检测蓝牙发现是否开启?

转载 作者:搜寻专家 更新时间:2023-11-01 08:10:53 25 4
gpt4 key购买 nike

我想检测蓝牙发现是否开启?可能吗?

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
}

Documentation of 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.

关于android - 检测蓝牙发现是否开启?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9772117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com