title: onLeScan never gets called android
body: <p>I have an app on an iPad that sends out Bluetooth LE information in place of its device name. I'm trying to capture that information in my Android code and update the UI in some way. Basically I need to scan for devices continuously and use the "device name" according to my protocol to update my Android UI. I know this isn't the right way to do things and I do plan to refactor both apps to correctly use Bluetooth LE, but I need this done soon and I don't have the time right now.</p>
  
  <p>In my code below I know that scanLeDevices is getting called due to some Logs I put in, but the print statement I have in onLeScan is never getting called. Can anybody please tell me why? I've been stuck on this for a long time...</p>
  
  <pre><code>public class MainActivity extends Activity {
      private static final String TAG = "...";
      List&lt;String&gt; listItems=new ArrayList&lt;String&gt;();
      ArrayAdapter&lt;String&gt; adapter;
  
      BluetoothManager mBluetoothManager;
      private BluetoothAdapter mBluetoothAdapter;
      TextView mainView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
          setContentView(R.layout.activity_main);
          setProgressBarIndeterminate(true);
  
          mBluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
          mBluetoothAdapter = mBluetoothManager.getAdapter();
          mainView = (TextView) findViewById(R.id.main_view);
  
          scanLeDevice(true);     
      }
  
      @Override
      protected void onResume() {
          super.onResume();
  
          if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
              //Bluetooth is disabled
              Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
              startActivity(enableBtIntent);
              finish();
              return;
          }
  
          if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
              Toast.makeText(this, "No LE Support.", Toast.LENGTH_SHORT).show();
              finish();
              return;
          }
  
          scanLeDevice(true);
      }
  
      private static final long SCAN_TIME = 1000;
      boolean mScanning = false;
      private void scanLeDevice(final boolean enable) {
          Log.i(null, "Inside scanLeDevice");
          if (enable) {
              // Stops scanning after a pre-defined scan period.
              mHandler.postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      mScanning = false;
                      Log.i(null, "Calling stopLeScan");
                      mBluetoothAdapter.stopLeScan(mLeScanCallback);
                  }
              }, SCAN_TIME);
  
              mScanning = true;
              Log.i(null, "Calling startLeScan");
              mBluetoothAdapter.startLeScan(mLeScanCallback);
          } else {
              mScanning = false;
              mBluetoothAdapter.stopLeScan(mLeScanCallback);
          }
      }
  
      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() {
                     Log.i(null, "INSIDE ONLESCAN");
                     //DO MY WORK
                 }
             });
         }
      };
  }
  </code></pre>