【发布时间】:2016-06-01 03:42:31
【问题描述】:
这是我在名为 PlayerService 的服务类中检索/创建/更新应用程序通知的方法:
import android.support.v7.app.NotificationCompat;
import android.app.Notification;
import android.app.NotificationManager;
// ...
private Notification getCompatNotification(String contentText) {
m_notificationBuilder
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("PlayerService")
.setContentText(contentText)
.setContentIntent(null)
.setWhen(0)
.setShowWhen(false)
.addAction(android.R.drawable.ic_media_previous, "", null)
.addAction((isPlaying() ? android.R.drawable.ic_media_pause : android.R.drawable.ic_media_play), "", null)
.addAction(android.R.drawable.ic_media_next, "", null)
.setStyle(new NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0, 1, 2)
.setShowCancelButton(true)
.setCancelButtonIntent(null))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_MAX);
Notification notification = m_notificationBuilder.build();
return notification;
}
现在,当媒体播放器活动打开但播放未开始时,通知会显示带有这 3 个操作按钮(上一个、播放/暂停、下一个)的大视图,但当开始播放时,通知视图会变为紧凑型和首先显示这 3 个按钮,然后再显示第一个和第二个。请查看图片。
测试设备具有 KitKat 4.4.4。
无播放
播放开始
更新通知:
private void updateNotification(String contentText){
nm.notify(NOTIFICATION_ID, getCompatNotification(contentText));
}
在onCreate():
@Override
public void onCreate() {
super.onCreate();
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
m_notificationBuilder = new NotificationCompat.Builder(this);
}
在onStartCommand():
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
startForeground(NOTIFICATION_ID, getCompatNotification("Test Content"));
return START_STICKY; // run until explicitly stopped.
}
无法弄清楚是什么问题。任何帮助都非常感谢。
【问题讨论】:
标签: android android-notifications android-appcompat