// 查找到设备和搜索完成action监听器
private BroadcastReceiver mReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
// 查找到设备action
if( BluetoothDevice.ACTION_FOUND.equals(action) )
{
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
mDevicesArrayAdapter.add(device.getName() + " " + device.getAddress());
/*if( device.getName().contains("HC-06") ) // 经常闪退,注释掉就没事了。
{
mBtAdapter.cancelDiscovery();
setProgressBarIndeterminateVisibility(false);
OnClickCloseScan( null );
}*/
}
else if( BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action) )
{
setProgressBarIndeterminateVisibility(false);
setTitle("选择要连接的设备");
if( mDevicesArrayAdapter.getCount() == 0 )
{
String noDevices = "没有找到新设备";
mDevicesArrayAdapter.add(noDevices);
}
}
}
};