title: Android - Bluetooth LE can't find any device
body: <p>I would like to use the Bluetooth Low Energy (BLE) technology to make connection between two supported <strong>phones</strong> (currently I would like to use it with only Android phones, iOS support is possible in the future). The client which starts the connection should be an Android device with API level 19 (KitKat) or above.</p>
  
  <p>I've read several tutorials and tried several examples about how to achieve a working Bluetooth LE scanning on Android (including Google's own sample project called <a href="https://github.com/googlesamples/android-BluetoothLeGatt" rel="nofollow noreferrer">BluetoothLeGatt</a>). The following things are already done in my test project, based on Android documentations and many SO questions and answers:</p>
  
  <ul>
  <li>Minimum SDK version is set on API level 18 (that's where Android started to support Bluetooth LE)</li>
  <li>The mandatory Bluetooth permissions (<code>BLUETOOTH</code> and <code>BLUETOOTH_ADMIN</code>) granted in <code>AndroidManifest.xml</code>, plus the <code>android.hardware.bluetooth_le</code> feature is set with <code>true</code> value</li>
  <li>The <code>ACCESS_FINE_LOCATION</code> and <code>ACCESS_COARSE_LOCATION</code> permissions are also needed on API level 23 and above - so they are in the manifest file too (with <code>uses-permission</code> AND <code>uses-permission-sdk-23</code> tags), plus the <code>android.hardware.location.gps</code> feature is set</li>
  <li>The user also is asked to grant the permissions mentioned above at app's first start</li>
  <li>Bluetooth and Location (GPS) are turned on</li>
  <li>Scanning for devices starts after permissions are granted (managed with clicking a button)</li>
  <li>On API level 21 and above the newer API methods are used instead of the ones deprecated since the same API level</li>
  </ul>
  
  <p>Despite all the things listed above, <strong>NO DEVICES FOUND AFTER STARTING THE SCAN</strong>. Currently I'm using a 6.0 (Marshmallow, API 23) device and everything seems fine - except finding the devices around me with Bluetooth turned on and set to always visible. But of course, from the device settings I can find all of them, so I don't understand what could be the missing / wrong thing (by the way, it's the first time I'm dealing with something related to Bluetooth... :) ). It looks like the scanning process starts seamlessly, but none of the callback methods are responding any single message or variable.</p>
  
  <p>And <strong>YES, I KNOW</strong>: there are a lot of questions on SO about this with people saying <em>"everything works after making the changes above"</em>... and unfortunately <strong>it does not work for me</strong>, so I'm a bit frustrated about this problem. If anyone reading this topic faced before with anything similar to this, and writes a comment or answer down there, I will really appreciate it! :)</p>
  
  <hr>
  
  <p><em>TO MAKE THE QUESTION SECTION EVEN LONGER:</em></p>
  
  <p>My activity:</p>
  
  <pre><code>import android.Manifest;
  import android.bluetooth.BluetoothAdapter;
  import android.bluetooth.BluetoothDevice;
  import android.bluetooth.BluetoothManager;
  import android.bluetooth.le.ScanCallback;
  import android.bluetooth.le.ScanResult;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Build;
  import android.os.Bundle;
  import android.os.Handler;
  import android.support.annotation.NonNull;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.Toast;
  
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
  
      private BluetoothAdapter mBluetoothAdapter;
      private boolean mScanning;
      private Handler mHandler;
  
      public static final int REQUEST_ENABLE_BT = 1;
      private static final int PERMISSION_REQUEST = 2;
      private static final long SCAN_PERIOD = 10000;
  
      private BluetoothAdapter.LeScanCallback mLeScanCallback;
      private ScanCallback scanCallback;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
              @Override
              public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
                  if (device != null)
                      Toast.makeText(MainActivity.this, "Device found", Toast.LENGTH_SHORT).show();
              }
          };
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {
              scanCallback = new ScanCallback() {
                  @Override
                  public void onScanResult(int callbackType, ScanResult result) {
                      Toast.makeText(MainActivity.this, "Device found", Toast.LENGTH_SHORT).show();
                      super.onScanResult(callbackType, result);
                  }
  
                  @Override
                  public void onBatchScanResults(List&lt;ScanResult&gt; results) {
                      Toast.makeText(MainActivity.this, "Batch returned", Toast.LENGTH_SHORT).show();
                      super.onBatchScanResults(results);
                  }
  
                  @Override
                  public void onScanFailed(int errorCode) {
                      Toast.makeText(MainActivity.this, errorCode, Toast.LENGTH_SHORT).show();
                      super.onScanFailed(errorCode);
                  }
              };
          }
  
          //Getting user's permission on API 23+
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
              requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST);
          }
  
          mHandler = new Handler();
  
          final BluetoothManager bluetoothManager =
              (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
          mBluetoothAdapter = bluetoothManager.getAdapter();
  
          if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
              Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
              startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
          }
  
          //A simple button which starts scan
          Button button = (Button) findViewById(R.id.button);
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  scanLeDevice(true);
              }
          });
      }
  
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
          if (requestCode == PERMISSION_REQUEST)
              Toast.makeText(this, "Permission settings changed", Toast.LENGTH_SHORT).show();
  
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == REQUEST_ENABLE_BT)
              Toast.makeText(this, "Bluetooth settings changed", Toast.LENGTH_SHORT).show();
  
          super.onActivityResult(requestCode, resultCode, data);
      }
  
      private void scanLeDevice(final boolean enable) {
          if (enable) {
              // Stops scanning after a pre-defined scan period.
              mHandler.postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      mScanning = false;
                      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP)
                          mBluetoothAdapter.getBluetoothLeScanner().stopScan(scanCallback);
                      else
                          mBluetoothAdapter.stopLeScan(mLeScanCallback);
                  }
              }, SCAN_PERIOD);
  
              mScanning = true;
  
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP)
                  mBluetoothAdapter.getBluetoothLeScanner().startScan(scanCallback);
              else
                  mBluetoothAdapter.startLeScan(mLeScanCallback);
  
          } else {
              mScanning = false;
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP)
                  mBluetoothAdapter.getBluetoothLeScanner().stopScan(scanCallback);
              else
                  mBluetoothAdapter.stopLeScan(mLeScanCallback);
          }
      }
  }
  </code></pre>
  
  <p>My manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.gery.example.bluelowexample"&gt;
  
      &lt;uses-permission android:name="android.permission.BLUETOOTH"/&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/&gt;
  
      &lt;uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/&gt;
  
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  
      &lt;uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-feature android:name="android.hardware.location.gps" /&gt;
  
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I think this logcat has everything that can help (filters are also turned off), but if you're missing something else, just ask for it... ;)</p>
  
  <pre><code>05-17 09:56:24.578 270-455/? I/BufferQueueProducer: [com.gery.example.bluelowexample/com.gery.example.bluelowexample.MainActivity](this:0x7f8ea54000,id:150,api:1,p:9879,c:270) queueBuffer: fps=0.03 dur=90743.60 max=9    0572.86 min=12.21
  05-17 09:56:24.578 9879-9879/com.gery.example.bluelowexample D/BluetoothAdapter: getLeState() returning 12
  05-17 09:56:24.580 9879-9879/com.gery.example.bluelowexample D/BluetoothAdapter: getLeState() returning 12
  05-17 09:56:24.580 9879-9879/com.gery.example.bluelowexample D/BluetoothAdapter: STATE_ON
  05-17 09:56:24.583 9879-9879/com.gery.example.bluelowexample D/BluetoothAdapter: getLeState() returning 12
  05-17 09:56:24.585 270-270/? D/MALI: eglCreateImageKHR:539: [Crop] 0 0 0 0  img[1080 1920] 
  05-17 09:56:24.590 10966-11003/? D/BtGatt.GattService: registerClient() - UUID=61759f7a-608a-43b4-b530-5487c6d83d95
  05-17 09:56:24.590 10966-10983/? D/BtGatt.GattService: onClientRegistered() - UUID=61759f7a-608a-43b4-b530-5487c6d83d95, clientIf=5
  05-17 09:56:24.591 9879-9900/com.gery.example.bluelowexample D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5
  05-17 09:56:24.592 10966-10977/? D/BluetoothAdapter: 203350351: getState(). Returning 12
  05-17 09:56:24.592 10966-10977/? D/BtGatt.GattService: start scan without filters
  05-17 09:56:24.593 940-1736/? D/AppOps: noteOperation: allowing code 1 uid 10141 package com.gery.example.bluelowexample
  05-17 09:56:24.593 10966-10986/? D/BtGatt.ScanManager: handling starting scan
  05-17 09:56:24.593 9879-9879/com.gery.example.bluelowexample I/BluetoothLeScanner: startRegisteration: mLeScanClients={com.gery.example.bluelowexample.MainActivity$2@f    05890c=android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper@c4ace96}
  05-17 09:56:24.594 10966-10986/? D/BluetoothAdapter: getLeState() returning 12
  05-17 09:56:24.595 10966-10986/? D/BluetoothAdapter: getLeState() returning 12
  05-17 09:56:24.595 270-270/? I/SurfaceFlinger: [Built-in Screen (type:0)] fps:0.287394,dur:6959.09,max:6952.73,min:6.36
  05-17 09:56:24.597 10966-10986/? D/BluetoothAdapter: getLeState() returning 12
  05-17 09:56:24.598 10966-10986/? I/BtGatt.ScanManager: configureScanFilters: client=com.android.bluetooth.gatt.ScanClient@24
  05-17 09:56:24.598 10966-10986/? I/BtGatt.ScanManager: getDeliveryMode:  DELIVERY_MODE_IMMEDIATE
  05-17 09:56:24.598 10966-10986/? I/BtGatt.ScanManager: gattClientScanFilterEnableNative(com.android.bluetooth.gatt.ScanClient@24,true);
  05-17 09:56:24.609 10966-10983/? D/BtGatt.GattService: onScanFilterEnableDisabled() - clientIf=5, status=0, action=1
  05-17 09:56:24.610 10966-10983/? D/BtGatt.ScanManager: callback done for clientIf - 5 status - 0
  05-17 09:56:24.610 10966-10986/? I/BtGatt.ScanManager: configureScanFilters: shouldUseAllPassFilter
  05-17 09:56:24.610 10966-10986/? I/BtGatt.ScanManager: getDeliveryMode:  DELIVERY_MODE_IMMEDIATE
  05-17 09:56:24.610 10966-10986/? D/BtGatt.ScanManager: configureFilterParamter 500 10000 1 0
  05-17 09:56:24.610 10966-10986/? I/BtGatt.ScanManager: configureFilterParamter: deliveryMode=0 ,rssiThreshold=-128
  05-17 09:56:24.610 10966-10986/? I/BtGatt.ScanManager: gattClientScanFilterParamAddNative
  05-17 09:56:24.612 10966-10983/? D/BtGatt.GattService: onScanFilterParamsConfigured() - clientIf=5, status=0, action=0, availableSpace=49
  05-17 09:56:24.612 10966-10983/? D/BtGatt.ScanManager: callback done for clientIf - 5 status - 0
  05-17 09:56:24.612 10966-10986/? I/BtGatt.ScanManager: gattClientScanNative(true);
  05-17 09:56:24.612 10966-10986/? D/BtGatt.ScanManager: configureRegularScanParams() - queue=1
  05-17 09:56:24.612 10966-10986/? D/BtGatt.ScanManager: configureRegularScanParams() - ScanSetting Scan mode=0 mLastConfiguredScanSetting=-2147483648
  05-17 09:56:24.613 10966-10986/? I/BtGatt.ScanManager: gattClientScanNative(false);
  05-17 09:56:24.613 10966-10986/? D/BtGatt.ScanManager: configureRegularScanParams - scanInterval = 8000configureRegularScanParams - scanWindow = 800
  05-17 09:56:24.613 10966-10986/? I/BtGatt.ScanManager: gattClientScanNative(true);
  05-17 09:56:24.613 10966-10983/? D/BtGatt.GattService: onScanParamSetupCompleted : 0
  05-17 09:56:24.614 940-971/? E/PROXIMITY: ProximitySensor: unknown event (type=3, code=0)
  05-17 09:56:24.615 940-963/? D/AutomaticBrightnessController: calculateAmbientLux: [0, 100]: lux=2745.0, weight=1005000.0
  05-17 09:56:24.615 940-963/? D/AutomaticBrightnessController: calculateAmbientLux: [-249, 0]: lux=2733.0, weight=2458999.5
  05-17 09:56:24.615 940-963/? D/AutomaticBrightnessController: calculateAmbientLux: [-499, -249]: lux=2750.0, weight=2406500.0
  05-17 09:56:24.615 940-963/? D/AutomaticBrightnessController: calculateAmbientLux: totalWeight=5870499.5, newAmbientLux=2742.023
  05-17 09:56:24.615 940-963/? D/AutomaticBrightnessController: updateAmbientLux: ambientLux=2742.023, timeToBrighten=4000, timeToDarken=8000, current=2691.0
  05-17 09:56:24.615 940-963/? D/AutomaticBrightnessController: updateAmbientLux: Scheduling ambient lux update for 76758807675880 (in 3999 ms)
  05-17 09:56:24.619 10966-10987/? W/bt_hci: filter_incoming_event command complete event with no matching command. opcode: 0x200c.
  </code></pre>