我为玩家设置了通知,我想在播放或暂停通知操作后更新图标。
这是我的通知代码。
private void showNotification(String title, Bitmap bitmap) {
//region Create Notification
MediaSessionCompat mediaSession = new MediaSessionCompat(getApplicationContext(), "session tag");
MediaSessionCompat.Token token = mediaSession.getSessionToken();
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this,"PRIMARY_CHANNEL")
.setSmallIcon(R.mipmap.ic_launcher_1)
.setLargeIcon(bitmap)
.setContentTitle("Simplay")
.setContentText(title)
.setOngoing(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(notifyPendingIntent)
.addAction(R.drawable.exo_controls_rewind,"",rewindPendingIntent)
**.addAction( R.drawable.exo_controls_pause,"",playPendingIntent)**
.addAction(R.drawable.exo_controls_fastforward,"",forwardPendingIntent)
.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
.setMediaSession(token))
.setPriority(NotificationCompat.PRIORITY_HIGH);
notificationManager = NotificationManagerCompat.from(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Notification";
String description = "";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel("PRIMARY_CHANNEL", name, importance);
channel.setDescription(description);
channel.enableLights(true);
channel.setShowBadge(false);
channel.setLockscreenVisibility(123);
NotificationManager notificationManager1 = getSystemService(NotificationManager.class);
notificationManager1.createNotificationChannel(channel);
}
notificationManager.notify(123, mBuilder.build());
//endregion
}
你应该使用
.addAction(getResources.getDrawable(R.drawable.exo_controls_pause),"",playPendingIntent)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)