我正在尝试发现附近的蓝牙设备。我遵循了教程,但是我无法弄清楚为什么从未调用{ favorites: [],
_id: 5cb32867d2dfea0cadd79ecb,
name: 'Anna',
userId:
'AF322',
__v: 0 }
方法。即使onReceive()
成功,也不会调用方法startDiscovery()
。我已经为清单添加了适当的权限
onReceive()
if(adapter.isDiscovering()) {
adapter.cancelDiscovery();
if (adapter.startDiscovery())
test.setText("Searching >>>");
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
Receiver receiver = new Receiver();
registerReceiver(receiver, filter);
}
}
if(!adapter.isDiscovering()) {
if (adapter.startDiscovery())
test.setText("Searching >>>");
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
Receiver receiver = new Receiver();
registerReceiver(receiver, filter);
}