mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-19 07:24:22 +01:00
committed by
GitHub
parent
18ad3d97bb
commit
1004a561fd
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user