近期公司有蓝牙设备项目,遇到个问题;
连接蓝牙设备的app在连接时,如遇到蓝牙设备的信号名称错误或蓝牙设备关闭时,app有一定概率出现程序闪退;
经查证原因出现在接收蓝牙信号的广播的地方,原代码如下:
public BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//g_Context.unregisterReceiver(this); —deleted by jerry
String action = intent.getAction();
String strDevName = new String();
if ( BluetoothDevice.ACTION_FOUND.equals(action) ) {
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
strDevName = device.getName();
if ( strDevName.equalsIgnoreCase(bt_Name)) {
if( mBluetoothAdapter != null