0

I have 2 separate services, one for starting bluetoothLeAdvertiser and others for bluetoothLeScanner.

Service class for using bluetoothLeScanner looks as follows

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    super.onStartCommand(intent, flags, startId)
    startScanning()
    return START_STICKY
}
private fun startScanning() {
    bluetoothAdapter?.bluetoothLeScanner?.startScan(scanCallBack)
    Toast.makeText(this.applicationContext, "Scanning Started", Toast.LENGTH_SHORT).show()
}

and Service class for bluetoothLeAdvertiser looks as follows

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    super.onStartCommand(intent, flags, startId)
    FileManagement.getInstance(applicationContext).writeToFile(TAG, "onStartCommand() called")
    startAdvertising()
    return START_STICKY
}
private fun startAdvertising() {
    bluetoothAdapter?.bluetoothLeAdvertiser?.let {
        val setting = AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(false)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
            .build()

        val data = AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(true)
            .addServiceUuid(ParcelUuid.fromString("00001827-0000-1000-8000-00805F9B34FB"))
            .build()

        it.startAdvertising(setting, data, advertiseCallback)
        Toast.makeText(this.applicationContext, "Advert Started", Toast.LENGTH_SHORT).show()
    }
}

The issue is between bluetoothLeScanner and bluetoothLeAdvertiser only one of the callbacks is getting triggered.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nik
  • 2,913
  • 7
  • 40
  • 66
  • The APIs may not allow the dual functionality to both scan and advertise at the same time. That being said it might be due to the power requirements as well. Try make them both low power. – Thomas Morris May 13 '20 at 15:50
  • @ThomasMorris That did not work... What I have observed is the only either of the callbacks is getting called (saw them in logs).. any idea? – Nik May 14 '20 at 22:30
  • Sorry it did'nt work, my next guess would be the dual functionality maybe a later feature in ble, therefore might require a higher API requirement. So possibly try on a "newer" phone may have a later update of ble. I am not sure if this is the case however, but could be. – Thomas Morris May 15 '20 at 07:01

0 Answers0