一、APP端调用
1、注册广播监听查找结果
//蓝牙发现设备和查找结束广播
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(BluetoothDevice.ACTION_FOUND);
intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(btReceiver, intentFilter);
BroadcastReceiver btReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device != null) {
//这里收到的是单条设备信息,可以放到List中进行刷新列表
//设备名称:device.getName()
//设备地址:device.getAddress()
if(device.getBondState() == BluetoothDevice.BOND_BONDED) {
//已配对设备
}
}
} else if (BluetoothAdapter.ACTION_DISCOV
版权声明:本文为c19344881x原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。