BluetoothAdapter.startDiscovery() 没有发现那些屏幕关闭的蓝牙设备(在我的例子中是智能手机)
BluetoothAdapter.startDiscovery() doesn't discovers those bluetooth devices(Smart Phones in my case) whose screen is off
我一直在尝试使用 bluetoothAdapter 的 startDiscovery() 函数发现所有相邻的蓝牙设备(在我的例子中是经典蓝牙)。但问题是,只发现那些在设置中打开蓝牙屏幕的设备,或者换句话说,所有关闭屏幕的智能手机都没有被发现。我想发现每一个蓝牙打开的相邻设备。以下是我用于完成上述工作的代码片段:
//Broadcast Receiver for getting bluetooth devices
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)){
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
System.out.println("A device was found!"+bluetoothDevice.getName());
}
}
};
//Registering the broadcast receiver
protected void onStart() {
super.onStart();
IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(broadcastReceiver, intentFilter);
}
//Calling the startDiscovery() function of the bluetoothAdapter
public void discoverDevices(View v){
bluetoothAdapter.startDiscovery();
System.out.println("Bluetooth Discovery has started");
}
我已经搜索了很多地方来获得这个但没有成功,任何线索都将非常有帮助。
Android developers API reference 明确说明如下:
Device discovery will only find remote devices that are currently discoverable (inquiry scan enabled). Many Bluetooth devices are not discoverable by default, and need to be entered into a special mode.
您可能不得不接受您尝试做的事情行不通的想法。
我一直在尝试使用 bluetoothAdapter 的 startDiscovery() 函数发现所有相邻的蓝牙设备(在我的例子中是经典蓝牙)。但问题是,只发现那些在设置中打开蓝牙屏幕的设备,或者换句话说,所有关闭屏幕的智能手机都没有被发现。我想发现每一个蓝牙打开的相邻设备。以下是我用于完成上述工作的代码片段:
//Broadcast Receiver for getting bluetooth devices
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)){
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
System.out.println("A device was found!"+bluetoothDevice.getName());
}
}
};
//Registering the broadcast receiver
protected void onStart() {
super.onStart();
IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(broadcastReceiver, intentFilter);
}
//Calling the startDiscovery() function of the bluetoothAdapter
public void discoverDevices(View v){
bluetoothAdapter.startDiscovery();
System.out.println("Bluetooth Discovery has started");
}
我已经搜索了很多地方来获得这个但没有成功,任何线索都将非常有帮助。
Android developers API reference 明确说明如下:
Device discovery will only find remote devices that are currently discoverable (inquiry scan enabled). Many Bluetooth devices are not discoverable by default, and need to be entered into a special mode.
您可能不得不接受您尝试做的事情行不通的想法。