mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Inline method in PlayerService that is used from on call site only
#cleanup #minor-release PiperOrigin-RevId: 505146915 (cherry picked from commit d7ef1ab5bd5a4508c0913011f5990bb03a57585a)
This commit is contained in:
parent
631ff809f5
commit
bfc4ed4dd4
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package androidx.media3.demo.session
|
package androidx.media3.demo.session
|
||||||
|
|
||||||
import android.app.Notification.BigTextStyle
|
|
||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent.*
|
import android.app.PendingIntent.*
|
||||||
@ -272,23 +271,17 @@ class PlaybackService : MediaLibraryService() {
|
|||||||
* background.
|
* background.
|
||||||
*/
|
*/
|
||||||
override fun onForegroundServiceStartNotAllowedException() {
|
override fun onForegroundServiceStartNotAllowedException() {
|
||||||
createNotificationAndNotify()
|
val notificationManagerCompat = NotificationManagerCompat.from(this@PlaybackService)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createNotificationAndNotify() {
|
|
||||||
var notificationManagerCompat = NotificationManagerCompat.from(this)
|
|
||||||
ensureNotificationChannel(notificationManagerCompat)
|
ensureNotificationChannel(notificationManagerCompat)
|
||||||
var pendingIntent =
|
val pendingIntent =
|
||||||
TaskStackBuilder.create(this).run {
|
TaskStackBuilder.create(this@PlaybackService).run {
|
||||||
addNextIntent(Intent(this@PlaybackService, MainActivity::class.java))
|
addNextIntent(Intent(this@PlaybackService, MainActivity::class.java))
|
||||||
|
|
||||||
val immutableFlag = if (Build.VERSION.SDK_INT >= 23) FLAG_IMMUTABLE else 0
|
val immutableFlag = if (Build.VERSION.SDK_INT >= 23) FLAG_IMMUTABLE else 0
|
||||||
getPendingIntent(0, immutableFlag or FLAG_UPDATE_CURRENT)
|
getPendingIntent(0, immutableFlag or FLAG_UPDATE_CURRENT)
|
||||||
}
|
}
|
||||||
|
val builder =
|
||||||
var builder =
|
NotificationCompat.Builder(this@PlaybackService, CHANNEL_ID)
|
||||||
NotificationCompat.Builder(this, CHANNEL_ID)
|
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
.setSmallIcon(R.drawable.media3_notification_small_icon)
|
.setSmallIcon(R.drawable.media3_notification_small_icon)
|
||||||
.setContentTitle(getString(R.string.notification_content_title))
|
.setContentTitle(getString(R.string.notification_content_title))
|
||||||
@ -299,6 +292,7 @@ class PlaybackService : MediaLibraryService() {
|
|||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
notificationManagerCompat.notify(NOTIFICATION_ID, builder.build())
|
notificationManagerCompat.notify(NOTIFICATION_ID, builder.build())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun ensureNotificationChannel(notificationManagerCompat: NotificationManagerCompat) {
|
private fun ensureNotificationChannel(notificationManagerCompat: NotificationManagerCompat) {
|
||||||
if (Util.SDK_INT < 26 || notificationManagerCompat.getNotificationChannel(CHANNEL_ID) != null) {
|
if (Util.SDK_INT < 26 || notificationManagerCompat.getNotificationChannel(CHANNEL_ID) != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user