content: package com.sample.android.bluetoothle.java;
  
  import android.annotation.SuppressLint;
  import android.app.ListActivity;
  import android.bluetooth.BluetoothAdapter;
  import android.bluetooth.le.BluetoothLeScanner;
  import android.bluetooth.le.ScanCallback;
  import android.bluetooth.le.ScanResult;
  import android.os.Handler;
  
  /**
   * Activity for scanning and displaying available BLE devices.
   */
  public class DeviceScanActivity extends ListActivity {
      // [START process_scan_result]
      private LeDeviceListAdapter leDeviceListAdapter;
  
      // Device scan callback.
      private ScanCallback leScanCallback =
              new ScanCallback() {
                  @Override
                  public void onScanResult(int callbackType, ScanResult result) {
                      super.onScanResult(callbackType, result);
                      leDeviceListAdapter.addDevice(result.getDevice());
                      leDeviceListAdapter.notifyDataSetChanged();
                  }
              };
      // [END process_scan_result]
  
      // [START start_and_stop_scan]
      private BluetoothLeScanner bluetoothLeScanner =
              BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner();
      private boolean mScanning;
      private Handler handler = new Handler();
  
      // Stops scanning after 10 seconds.
      private static final long SCAN_PERIOD = 10000;
  
      @SuppressLint("MissingPermission")
      private void scanLeDevice() {
          if (!mScanning) {
              // Stops scanning after a pre-defined scan period.
              handler.postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      mScanning = false;
                      bluetoothLeScanner.stopScan(leScanCallback);
                  }
              }, SCAN_PERIOD);
  
              mScanning = true;
              bluetoothLeScanner.startScan(leScanCallback);
          } else {
              mScanning = false;
              bluetoothLeScanner.stopScan(leScanCallback);
          }
      }
      // [END start_and_stop_scan]
  }
  