AndroidAPS/app/src/main/java/info/nightscout/androidaps/receivers/BTReceiver.kt

25 lines
957 B
Kotlin
Raw Normal View History

2020-04-02 18:48:37 +02:00
package info.nightscout.androidaps.receivers
import android.bluetooth.BluetoothDevice
import android.content.Context
import android.content.Intent
import dagger.android.DaggerBroadcastReceiver
import info.nightscout.androidaps.events.EventBTChange
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import javax.inject.Inject
class BTReceiver : DaggerBroadcastReceiver() {
@Inject lateinit var rxBus: RxBusWrapper
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
val device : BluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)
when (intent.action) {
BluetoothDevice.ACTION_ACL_CONNECTED ->
rxBus.send(EventBTChange(EventBTChange.Change.CONNECT, device.name))
BluetoothDevice.ACTION_ACL_DISCONNECTED ->
rxBus.send(EventBTChange(EventBTChange.Change.DISCONNECT, device.name))
}
}
}