@@ -56,7 +56,7 @@ public class MultipleBleService extends Service implements Constants, BleListene
5656 private BluetoothManager mBluetoothManager ;
5757 private BluetoothAdapter mBluetoothAdapter ;
5858 private Map <String , BluetoothGatt > mBluetoothGattMap ;
59- private List <BluetoothDevice > mScanLeDeviceList ;
59+ private List <BluetoothDevice > mScanLeDeviceList = new ArrayList <>() ;
6060 private boolean isScanning ;
6161 private List <String > mConnectedAddressList ;//Already connected remote device address
6262 //Stop scanning after 10 seconds.
@@ -190,9 +190,6 @@ public void run() {
190190// mBluetoothAdapter.getBluetoothLeScanner().stopScan(mLeScanCallback);
191191 }
192192 }, scanPeriod );
193- if (mScanLeDeviceList == null ) {
194- mScanLeDeviceList = new ArrayList <>();
195- }
196193 mScanLeDeviceList .clear ();
197194 isScanning = true ;
198195 if (Build .VERSION .SDK_INT >= 21 ) {
@@ -610,7 +607,7 @@ public List<BluetoothGattService> getSupportedGattServices(String address) {
610607 public void onLeScan (BluetoothDevice device , int rssi , byte [] scanRecord ) {
611608 Log .i (TAG , "device name: " + device .getName () + ", address: " + device .getAddress ());
612609// Log.i(TAG, "mScanLeDeviceList.contains(device): " + mScanLeDeviceList.contains(device));
613- if (mScanLeDeviceList .contains (device )) return ;
610+ if (device == null || mScanLeDeviceList .contains (device )) return ;
614611 mScanLeDeviceList .add (device );
615612 if (mOnLeScanListener != null ) {
616613 mOnLeScanListener .onLeScan (device , rssi , scanRecord );
0 commit comments