title: Recieving incorrect results after BLE scan in android
body: <p>I am using the following code to scan all the nearby BLE devices</p>
  <p>here is the code.</p>
  <pre><code>    package com.btexample;
  
      import android.Manifest;
      import android.app.Activity;
      import android.bluetooth.BluetoothAdapter;
      import android.bluetooth.BluetoothManager;
      import android.bluetooth.le.BluetoothLeScanner;
      import android.bluetooth.le.ScanCallback;
      import android.bluetooth.le.ScanFilter;
      import android.bluetooth.le.ScanResult;
      import android.bluetooth.le.ScanSettings;
      import android.content.Context;
      import android.content.Intent;
      import android.content.pm.PackageManager;
      import android.os.Handler;
      import androidx.annotation.NonNull;
      import androidx.core.app.ActivityCompat;
      import androidx.core.content.ContextCompat;
      import com.facebook.react.bridge.ActivityEventListener;
      import com.facebook.react.bridge.ReactApplicationContext;
      import com.facebook.react.bridge.ReactContextBaseJavaModule;
      import com.facebook.react.bridge.ReactMethod;
      import com.facebook.react.bridge.Callback;
      import com.facebook.react.bridge.WritableMap;
      import com.facebook.react.bridge.WritableNativeMap;
      import java.util.ArrayList;
      import java.util.List;
      
      
      public class MyBluetooth extends ReactContextBaseJavaModule implements ActivityEventListener {
  
  
      private ReactApplicationContext context;
      private static final int PERMISSION_REQUEST_CODE = 200;
      private static final int REQUEST_ENABLE_BT = 10112;
      private String[] permissions = new String[]{Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN};
      private BluetoothManager bluetoothManager;
      private BluetoothAdapter bluetoothAdapter;
      private BluetoothLeScanner bluetoothLeScanner;
      private Callback scanSuccessCallBack,scanFailedCallBack;
  
      public MyBluetooth(ReactApplicationContext reactContext) {
          super(reactContext);
          context = reactContext;
          bluetoothManager =
                  (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
          bluetoothAdapter = bluetoothManager.getAdapter();
          bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
      }
  
      @NonNull
      @Override
      public String getName() {
          return &quot;MyBluetooth&quot;;
      }
  
  
  
  
      @ReactMethod
      public void turnOnBluetooth() {
          if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
              Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
              getCurrentActivity().startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
          }
      }
  
      private WritableMap convertJsonToMap(String name) {
          WritableMap map = new WritableNativeMap();
          map.putString(&quot;device_name&quot;, name);
          return map;
      }
  
      @ReactMethod
      private void requestGPSPermissions() {
          boolean permissionCheck =
                  ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
                          != PackageManager.PERMISSION_GRANTED
                          &amp;&amp;
                          ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION)
                                  != PackageManager.PERMISSION_GRANTED;
  
  
          if (permissionCheck) {
  
              ActivityCompat.requestPermissions(getCurrentActivity(), new String[]{
                              Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
                      },
                      PERMISSION_REQUEST_CODE);
  
          }
      }
  
  
      private boolean mScanning = false,isInvoked;
      private Handler handler;
  
      @ReactMethod
      public void scanLeDevice(int scanSeconds,Callback scanSuccessCallBack,Callback scanFailedCallBack) {
          if (!mScanning) {
              // Stops scanning after a pre-defined scan period.
              this.scanSuccessCallBack  = scanSuccessCallBack;
              this.scanFailedCallBack  = scanFailedCallBack;
              isInvoked = false;
              handler = new Handler();
              handler.postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      if(mScanning) {
                          bluetoothLeScanner.stopScan(leScanCallback);
                          mScanning = false;
                          if(!isInvoked){
                              scanFailedCallBack.invoke(&quot;No results found&quot;);
                          }
                      }
                  }
              }, scanSeconds*1000);
  
              mScanning = true;
              List&lt;ScanFilter&gt; filters = new ArrayList&lt;ScanFilter&gt;();
  
              ScanSettings settings = new ScanSettings.Builder()
                      .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                      .setReportDelay(1000)
                      .build();
  
  
  
              bluetoothLeScanner.startScan(filters, settings, leScanCallback);
          } else {
              mScanning = false;
              bluetoothLeScanner.stopScan(leScanCallback);
              scanFailedCallBack.invoke(&quot;Already scanning&quot;);
          }
      }
  
  
      private ScanCallback leScanCallback = new ScanCallback() {
  
  
          @Override
          public void onBatchScanResults(List&lt;ScanResult&gt; results) {
              if(results.size() &gt; 0 &amp;&amp; mScanning) {
                  mScanning = false;
                  if(!isInvoked){
                      scanSuccessCallBack.invoke(&quot;results found&quot;);
                      isInvoked = true;
                      bluetoothLeScanner.stopScan(leScanCallback);
                      handler.removeCallbacksAndMessages(null);
                  }
              }
          }
  
          @Override
          public void onScanFailed(int errorCode) {
              scanFailedCallBack.invoke(&quot;Scan failed&quot;);
          }
      };
  
  
      @Override
      public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
  
      }
  
      @Override
      public void onNewIntent(Intent intent) {
  
      }
  }
  </code></pre>
  <p>Now,</p>
  <ol>
  <li><p>As of now I don't have any peripheral device so I am using an app as a simulatore
  link: <a href="https://play.google.com/store/apps/details?id=com.ble.peripheral.sim&amp;hl=en_IN&amp;gl=US" rel="nofollow noreferrer">https://play.google.com/store/apps/details?id=com.ble.peripheral.sim&amp;hl=en_IN&amp;gl=US</a></p>
  </li>
  <li><p>Now Scanning with another App <a href="https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner&amp;hl=en_IN&amp;gl=US" rel="nofollow noreferrer">https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner&amp;hl=en_IN&amp;gl=US</a>  on another device I am receiving correct results</p>
  </li>
  <li><p>Now scanning with my app again receiving the results.</p>
  </li>
  </ol>
  <p>Now the main problem is.</p>
  <ol>
  <li><p>when I turn off the simulator app and also uninstall it, I am still getting it as the result in my app but not in that scanner App.</p>
  </li>
  <li><p>Also my app is receiving random devices with deviceName=null (also a lot of things are null) and these random devices don't Appear in that Scanner App.</p>
  </li>
  <li><p>when I remove the filters and the settings from starScan();</p>
  <p>e.g.</p>
  <p>bluetoothLeScanner.startScan(filters, settings, leScanCallback);</p>
  </li>
  </ol>
  <p>the call back for onBatchScanResults() never recived.</p>
  <ol start="4">
  <li>Remove the Simulator App from the Devices, Fresh Install My app in the third device still getting 1 or 2 random results with null deviceName</li>
  </ol>
  <p>NOTE : I am checking the results in the debugger of android studio</p>
  <p>Please Help me thanks in Advance</p>