detect bluetooth Le devices in Android

后端 未结 4 2139
一向
一向 2021-02-06 07:24

I\'m a beginner in android app development. I\'ve tried reading the documentation but am getting nowhere (functions in Android\'s tutorial such as StartLeScan() hav

4条回答
  •  温柔的废话
    2021-02-06 07:57

    I had been playing with BLE scan for a while until I got the simplest solution from Nordic library.

    Add a line to your build.gradle:

    dependencies {
      ....
      compile 'no.nordicsemi.android.support.v18:scanner:1.0.0'
    }
    

    And use BluetoothLeScannerCompat:

    import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat;
    
    ...
    BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
    scaner.startScan(new ScanCallback { ...});
    

    And the library does all job.

提交回复
热议问题