diff --git a/app/build.gradle b/app/build.gradle index f3b25e48..76c3b034 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { defaultConfig { minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 31 renderscriptTargetApi 29//must match target sdk and build tools vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bf69e2ee..e785fea3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -262,6 +262,7 @@ android:enabled="true" android:exported="true" android:label="@string/app_name" + android:foregroundServiceType="mediaPlayback" tools:ignore="ExportedService"> diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotification.kt b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotification.kt index 4d0476ca..5557a285 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotification.kt +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotification.kt @@ -19,6 +19,7 @@ import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context.NOTIFICATION_SERVICE +import android.content.pm.ServiceInfo import android.os.Build import androidx.annotation.RequiresApi import code.name.monkey.retromusic.R @@ -62,7 +63,15 @@ abstract class PlayingNotification { } if (newNotifyMode == NOTIFY_MODE_FOREGROUND) { - service.startForeground(NOTIFICATION_ID, notification) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + service.startForeground( + NOTIFICATION_ID, + notification, + ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK + ) + } else { + service.startForeground(NOTIFICATION_ID,notification) + } } else if (newNotifyMode == NOTIFY_MODE_BACKGROUND) { notificationManager!!.notify(NOTIFICATION_ID, notification) }