Browse Source

上传通知更新

newdev_shunjiawei
liwei1dao 1 year ago
parent
commit
30de2439a8
  1. 21
      local_plugins/music_service/android/src/main/kotlin/com/yunqiinnovation/music_service/MusicService.kt

21
local_plugins/music_service/android/src/main/kotlin/com/yunqiinnovation/music_service/MusicService.kt

@ -30,6 +30,7 @@ class MusicService : MediaBrowserServiceCompat() {
private const val TAG = "MusicService"
private const val CHANNEL_ID = "music_media_service_channel"
private const val NOTIFICATION_ID = 1002
private const val DELETE_ACTION = "com.yunqiinnovation.music_service.DELETE_NOTIFICATION"
private val isRunning = AtomicBoolean(false)
private var currentUrlInternal: String? = null
@ -145,7 +146,22 @@ class MusicService : MediaBrowserServiceCompat() {
if (currentStatus) PlaybackStateCompat.ACTION_PAUSE else PlaybackStateCompat.ACTION_PLAY
)
val nextIntent = mediaButtonPendingIntent(PlaybackStateCompat.ACTION_SKIP_TO_NEXT)
// 添加删除按钮Action
// 创建删除通知的PendingIntent
val deleteIntent = Intent(this, MusicService::class.java).apply {
action = DELETE_ACTION
}
val deletePendingIntent = PendingIntent.getService(
this,
0,
deleteIntent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
)
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle(title)
.setContentText(artist)
@ -163,7 +179,10 @@ class MusicService : MediaBrowserServiceCompat() {
playPauseIntent
)
.addAction(android.R.drawable.ic_media_next, "下一首", nextIntent)
// 添加删除通知按钮
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "删除", deletePendingIntent)
.setOngoing(currentStatus)
.setDeleteIntent(deletePendingIntent) // 设置通知被滑动删除时的行为
// 异步加载封面图
if (!coverUrl.isNullOrEmpty()) {

Loading…
Cancel
Save