尝试过滤蓝牙扫描结果时崩溃

Crash when attempting to filter results of Bluetooth scan

我正在为 android 编写一个玩具应用程序,它使用蓝牙从健身手环读取特征,因此我只对这些手环感兴趣,所以我尝试使用以下代码过滤我的扫描结果:

private BluetoothAdapter.LeScanCallback mLeScanCallback =
            new BluetoothAdapter.LeScanCallback() {

        @Override
        public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (device.getAddress().contains("88:0F:10") | device.getName().equals("MI")) { //For some reason this crashes the app
                        mLeDeviceListAdapter.addDevice(device);
                        mLeDeviceListAdapter.notifyDataSetChanged();
                    }
                }
            });
        }
    };

问题是,当我 运行 此代码时,应用程序立即崩溃,特别是在有条件的情况下,没有它,应用程序 运行 会完美。 是什么导致了这次崩溃?

or 条件应该有两个管道字符:

if (device.getAddress().contains("88:0F:10") || device.getName().equals("MI"))

用下一种方式重写条件:

if (device.getAddress() != null && device.getAddress().contains("88:0F:10") && device.getName() != null && device.getName().equals("MI")) {
...
}

方法BluetoothDevice.getName()可以return null。