title: Bluetooth does not scan near by devices in background mode android 11+
body: <p>I try to scan the nearby Bluetooth device in background mode, it is not working on some devices like android 11+.</p>
  <p>here is my sample code, working in the foreground very well</p>
  <p>// granted all permission
  
  </p>
  <pre><code> &lt;uses-permission android:name=&quot;android.permission.FOREGROUND_SERVICE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_BACKGROUND_LOCATION&quot; /&gt;
   &lt;!--BLUETOOTH PERMISSION--&gt;
      &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_ADMIN&quot; /&gt;
      &lt;!-- Needed only if your app looks for Bluetooth devices.
               If your app doesn't use Bluetooth scan results to derive physical
               location information, you can strongly assert that your app
               doesn't derive physical location. --&gt;
      &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_SCAN&quot; /&gt;
      &lt;!-- Needed only if your app makes the device discoverable to Bluetooth
        devices. --&gt;
      &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_ADVERTISE&quot; /&gt;
      &lt;!-- Needed only if your app communicates with already-paired Bluetooth
             devices. --&gt;
      &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_CONNECT&quot; /&gt;
      &lt;!--bibo01 : hardware option--&gt;
      &lt;uses-feature android:name=&quot;android.hardware.bluetooth&quot; android:required=&quot;false&quot;/&gt;
      &lt;uses-feature android:name=&quot;android.hardware.bluetooth_le&quot; android:required=&quot;false&quot;/&gt;
  </code></pre>
  <p>// for Scanning Ble Device in api version above 21</p>
  <pre><code>private var settings: ScanSettings?         = null
  private val scanFilters = java.util.ArrayList&lt;ScanFilter&gt;()
  private var mLEScanner: BluetoothLeScanner? = null
  private var adapter: BluetoothAdapter?        = null
  
  
  
  
      val adapterBlu = applicationContextNew.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
      adapter = adapterBlu.adapter
  
      mLEScanner = adapter!!.bluetoothLeScanner
      settings   = ScanSettings.Builder()
          //.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)
          .build()
      //scan specified devices only with ScanFilter
      val scanFilter = ScanFilter.Builder()
          //.setDeviceName(&quot;BIBO 1&quot;)
          .build()
      scanFilters.add(scanFilter)
  
  
  
    mLEScanner = adapter!!.bluetoothLeScanner
      settings   = ScanSettings.Builder()
          .build()
      //scan specified devices only with ScanFilter
      val scanFilter = ScanFilter.Builder()
          .build()
      scanFilters.add(scanFilter)
  </code></pre>
  <p>// scan:</p>
  <pre><code> mLEScanner!!.startScan(scanFilters, settings, highScanCallback)
  
  
  //high Scan callback
  private val highScanCallbackClackmass =
      object : ScanCallback() {
          override fun onScanResult(callbackType: Int, result: ScanResult) {
  
              
              if (result.device.name != null &amp;&amp; result.device.address != null){
                  if (&quot;BIBO 1&quot; == result.device.name.toString()) {
                      //globalDeviceAddress = result.device.address.toString()
                  }
              }
  
          }
      }
  </code></pre>
  <p>also tried screen wake solution: (working below android 10)</p>
  <pre><code>val pm: PowerManager = getSystemService(POWER_SERVICE) as PowerManager
                  val isScreenOn: Boolean = pm.isInteractive // check if screen is on
                  if (!isScreenOn) {
                      val wl: PowerManager.WakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP, &quot;myApp:notificationLock&quot;)
                      wl.acquire(9000) //set your time in milliseconds
                  }
  </code></pre>