[英]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
}
int android.bluetooth.BluetoothAdapter.getScanMode()
获取本地蓝牙适配器的当前蓝牙扫描模式。
蓝牙扫描模式确定本地适配器是否可连接和/或可从远程蓝牙设备发现。
bluetoothAdapter.isDiscovering();
应该做你想要的。 您可以通过以下方式获取默认的BluetoothAdapter对象:
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
您可以在Android BluetoothAdapter文档中了解这两种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.