Prevent crash if bluetooth isn't available on the device
This commit is contained in:
parent
17547753b4
commit
8dfbe98396
2 changed files with 4 additions and 2 deletions
|
@ -48,7 +48,8 @@ class Api21Compatibility {
|
|||
companion object {
|
||||
@SuppressLint("MissingPermission")
|
||||
fun getDeviceName(context: Context): String {
|
||||
var name = BluetoothAdapter.getDefaultAdapter().name
|
||||
val adapter = BluetoothAdapter.getDefaultAdapter()
|
||||
var name = adapter?.name
|
||||
if (name == null) {
|
||||
name = Settings.Secure.getString(
|
||||
context.contentResolver,
|
||||
|
|
|
@ -34,7 +34,8 @@ class Api25Compatibility {
|
|||
context.contentResolver, Settings.Global.DEVICE_NAME
|
||||
)
|
||||
if (name == null) {
|
||||
name = BluetoothAdapter.getDefaultAdapter().name
|
||||
val adapter = BluetoothAdapter.getDefaultAdapter()
|
||||
name = adapter?.name
|
||||
}
|
||||
if (name == null) {
|
||||
name = Settings.Secure.getString(
|
||||
|
|
Loading…
Reference in a new issue