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.