2015-09-04 62 views
0

我爲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(); 
        } 
       } 
      }); 
     } 
    }; 

麻煩的是,當我運行這段代碼的應用程序立即崩潰,特別是在有條件的,沒有它的應用程序運行非常好。 什麼可能導致這次崩潰?

+0

安置自己的logcat – Rami

回答

2

重寫條件:

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

方法BluetoothDevice.getName()可以返回null。

+0

完美,謝謝錯誤複製! – Awia

1

的或有條件的應該有兩個管字符:

如果(device.getAddress()包含( 「88:0F:10」。)|| device.getName()等於( 「MI」在明年的方式))

+0

這樣做,這是從Android的工作室是我不好 – Awia