title: Android BLE scan with screen off (with Galaxy)
body: <p>Im working with Galaxy S10, android 10. From <a href="https://stackoverflow.com/questions/48077690/ble-scan-is-not-working-when-screen-is-off-on-android-8-1-0">here</a>, BLE scan with Samsung devices need non-empty scan filter to scan in screen-off state.</p>
  <p>Below is my AdvertiseData and ScanFilter code.</p>
  <pre><code>ParcelUuid aaUuid = ParcelUuid.fromString(&quot;0000aa11-0000-1000-8000-00805F9B34FB&quot;);
  
  AdvertiseData advertiseData = new AdvertiseData.Builder()
                  .setIncludeDeviceName(true) 
                  .addServiceUuid(aaUuid)
                  .build();
  
  ScanFilter scanFilter = new ScanFilter.Builder()
                  .setServiceUuid(aaUuid)
                  .build();
  </code></pre>
  <p>With screen on, it works well. However, with screen off, it doesn't work too.</p>
  <p>I set 10 times scanning to check this. At first, screen on, it works well. When it became screen-off, the first scan works good. But next scan result does not appear and it just start next scanning process (without result).</p>
  <p>'WakeLock' for each scanning repetition makes same result. How to solve this problem?</p>
  <hr />
  <p>Add 1. I used WorkManager to handle background process. Then I was looking for another method.</p>
  <p>Add 2. Below is my scancallback code.</p>
  <pre><code>private ScanCallback mScanCallback = new ScanCallback() {
          @Override
          public void onScanResult(int callbackType, ScanResult result) {
              super.onScanResult(callbackType, result);
              if (result.getDevice().getName() != null)
                  setBleScanResult(result);
          }
  
          @Override
          public void onBatchScanResults(List&lt;ScanResult&gt; results) {
              super.onBatchScanResults(results);
          }
  
          @Override
          public void onScanFailed(int errorCode) {
              super.onScanFailed(errorCode);
              Log.d(&quot;LOG_BLESCANNING_onScanFailed&quot;, &quot;Error Code : &quot; + errorCode);
          }
      };
  </code></pre>
  <p>Add 3. Below is my log when screen off</p>
  <pre><code>...
  D/Worker: ============ Bluetooth Scanning start ============
  D/LOG_BluetoothScan: Bluetooth scanning started successfully
  D/BluetoothAdapter: isLeEnabled(): ON
  D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=4 mScannerId=0
  D/BluetoothAdapter: isLeEnabled(): ON
  D/LOG_BluetoothScan: Bluetooth scanning stopped
  ...
  </code></pre>
  <p>and screen on</p>
  <pre><code>D/Worker: ============ Bluetooth Scanning start ============
  D/LOG_BluetoothScan: Bluetooth scanning started successfully
  D/BluetoothAdapter: isLeEnabled(): ON
  D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=4 mScannerId=0
  D/LOG_BluetoothScan: W S10 | [00001111-0000-1000-8000-00805f9b34fb] | 55:40:DE:86:D0:03
  D/LOG_BluetoothScan: W S10 | [00001111-0000-1000-8000-00805f9b34fb] | 55:40:DE:86:D0:03
  D/LOG_BluetoothScan: W S10 | [00001111-0000-1000-8000-00805f9b34fb] | 55:40:DE:86:D0:03
  D/LOG_BluetoothScan: W S10 | [00001111-0000-1000-8000-00805f9b34fb] | 55:40:DE:86:D0:03
  D/BluetoothAdapter: isLeEnabled(): ON
  D/LOG_BluetoothScan: Bluetooth scanning stopped
  </code></pre>
  <p>Add 4. I'm curious about 'Why is this problem only in the ble scanning?' I check ble advertising in screen off state does not have any problem.</p>
  <hr />
  <p>Add 5. Advertising also has problem... but it is not essential. I think MainActivity - Worker (from WorkManager) connection is bad to control this situation.</p>