android蓝牙app连接外设时崩溃问题

  • Post author:
  • Post category:其他


近期公司有蓝牙设备项目,遇到个问题;

连接蓝牙设备的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



版权声明:本文为fanbiqi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。