Shows prompt when Bluetooth is off and trying to add device

When trying to add a Meshtastic device, the app will check if bluetooth is turned on, if it isn't then it will display a message.
pull/469/head
Ayub 2022-08-23 16:52:39 +01:00
rodzic db1218c46a
commit e4b2649807
1 zmienionych plików z 14 dodań i 0 usunięć

Wyświetl plik

@ -1,5 +1,6 @@
package com.geeksville.mesh.ui
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.companion.CompanionDeviceManager
import android.content.*
@ -475,6 +476,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
if (!myActivity.hasScanPermission()) {
myActivity.requestScanPermission()
} else {
checkBTEnabled()
if (!scanModel.hasCompanionDeviceApi) checkLocationEnabled()
scanLeDevice()
}
@ -501,6 +503,18 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
}
}
private fun checkBTEnabled(
warningReason: String = getString(R.string.requires_bluetooth)
) {
var btAdapter = BluetoothAdapter.getDefaultAdapter();
if (!(btAdapter.isEnabled())) {
warn("We need bluetooth")
showSnackbar(warningReason)
}
}
private val updateProgressFilter = IntentFilter(SoftwareUpdateService.ACTION_UPDATE_PROGRESS)
private val updateProgressReceiver: BroadcastReceiver = object : BroadcastReceiver() {