我正在为Android构建一个音乐播放器。在后台运行时,我想在播放音乐时禁用滑动通知但是当用户暂停音乐时应该启用滑动。
当音乐暂停时,我尝试在“通知”构建器上的setOnGoing(false)
更新setOnGoing(true)
,但似乎无法正常工作。它仍然没有启用滑动通知。
Notification notification = mBuilder
.setSmallIcon(R.drawable.play_icon)
.setOngoing(true)
.setAutoCancel(false)
.setPriority(PRIORITY_MAX)
.build();
暂停播放时执行此操作:
Notification notif = mBuilder.setOngoing(false).build();
notif.bigContentView = mRemoteViews;
notif.contentView = mRemoteViewsCollapsed;
mBuilder是类级别Notification.Builder
这会正确更新contentView,但不会更改其正在进行的状态
答案 0 :(得分:0)
尝试设置标志
Notification notification = new Notification(R.drawable.play_icon, whatever, when);
notification.flags = Notification.FLAG_ONGOING_EVENT;
答案 1 :(得分:0)
我尝试过这种方法,对我有用:
let mut v:Vec<Option<ResourceEnum>> = city.buildings.iter().map(|f| f.produce()).collect();
v.drain(..).for_each(|r| city.add_resource(r));
播放器功能:
Notification notification = mBuilder
.setSmallIcon(R.drawable.play_icon)
.setPriority(PRIORITY_MAX)
.build();
//setOngoing after building
notification = builder.build();
builder.setOngoing(true);