Migration to latest BLEK (#132)

* Migration to latest BLEK

* Clean up
This commit is contained in:
Aleksander Nowakowski
2023-12-21 22:55:47 +01:00
committed by GitHub
parent 18ad3d97bb
commit 1004a561fd
28 changed files with 163 additions and 183 deletions

View File

@@ -40,11 +40,8 @@ android {
dependencies {
implementation(project(":lib_ui"))
implementation(libs.nordic.ble.common)
implementation(libs.nordic.ble.ktx)
implementation(libs.nordic.blek.uiscanner)
implementation(libs.nordic.blek.core)
implementation(libs.androidx.lifecycle.service)

View File

@@ -65,7 +65,7 @@ abstract class NotificationService : LifecycleService() {
private fun startForegroundService() {
// when the activity closes we need to show the notification that user is connected to the peripheral sensor
// We start the service as a foreground service as Android 8.0 (Oreo) onwards kills any running background services
val notification = createNotification(R.string.csc_notification_connected_message, 0)
val notification = createNotification(R.string.csc_notification_connected_message)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForeground(NOTIFICATION_ID, notification)
} else {
@@ -81,7 +81,7 @@ abstract class NotificationService : LifecycleService() {
// when the activity rebinds to the service, remove the notification and stop the foreground service
// on devices running Android 8.0 (Oreo) or above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
stopForeground(true)
stopForeground(STOP_FOREGROUND_REMOVE)
} else {
cancelNotification()
}
@@ -92,9 +92,8 @@ abstract class NotificationService : LifecycleService() {
*
* @param messageResId the message resource id. The message must have one String parameter,<br></br>
* f.e. `<string name="name">%s is connected</string>`
* @param defaults
*/
private fun createNotification(messageResId: Int, defaults: Int): Notification {
private fun createNotification(messageResId: Int): Notification {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(CHANNEL_ID)
}
@@ -111,6 +110,7 @@ abstract class NotificationService : LifecycleService() {
.build()
}
@Suppress("SameParameterValue")
@RequiresApi(Build.VERSION_CODES.O)
private fun createNotificationChannel(channelName: String) {
val channel = NotificationChannel(