27 lines
805 B
Kotlin
27 lines
805 B
Kotlin
package com.example.tvcontroller.data
|
|
|
|
import android.util.Log
|
|
|
|
class BluetoothDevice(name: String?, address: String?) {
|
|
private var _name: String? = name
|
|
private var _address: String? = address
|
|
|
|
fun getName(): String {
|
|
return if (_name.isNullOrEmpty()) getAddress() else _name!!
|
|
}
|
|
|
|
fun getAddress(): String {
|
|
return if (_address == null) "" else _address!!
|
|
}
|
|
|
|
companion object {
|
|
fun fromBluetoothDevice(device: android.bluetooth.BluetoothDevice): BluetoothDevice {
|
|
try {
|
|
return BluetoothDevice(device.name, device.address)
|
|
} catch (e: SecurityException) {
|
|
Log.e("BluetoothDevice", "Error creating BluetoothDevice", e)
|
|
}
|
|
return BluetoothDevice(null, null)
|
|
}
|
|
}
|
|
} |