-1
I am learning about Bluetooth in Kotlin and was reading this Google document about Bluetoothadapter https://developer.android.com/reference/android/bluetooth/BluetoothAdapter. I started implementing code for Android devices with API 6.0 (higher than JELLY_BEAN_MR1) and have some problems getting Bluetoothmanager. Here’s the code I’m working on:
lateinit var mBluetoothManager:BluetoothManager
fun foo(context:Context){
this.mBluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE)
}
Android Studio shows that it is a type incompatibility (required: Bluetoothmanager, Founded: Any!). So, how can I get the instance of Bluetoothmanager, I did something wrong? Why I need to connect this way using Systemservice and not that way:
var mBluetoothManager = BluetoothManager()
?
So when I change context I need to call getSystemService again?
– Jackjoss