zhangxian9s08
zhangxian9s08
2017-10-21 12:51

蓝牙闪退问题:在BroadcastReceiver 中要匹配特殊的蓝牙设备名称时闪退

  • 蓝牙闪退

// 查找到设备和搜索完成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);
            }
        }
    }
};
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答