我试图通过滑动关闭通知,但它只是不会关闭。我已经尝试设置正确的标志以及将OnGoing设置为false但我没有运气。
这是我的代码:
Notification notification = new Notification.Builder(getBaseContext())
.setSmallIcon(R.drawable.appicon)
.setContentTitle("My notification")
.setContent(remoteViews)
.setAutoCancel(true)
.setOngoing(false)
.build();
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
// Additional code
Intent playpause = new Intent();
playpause.setAction("com.eciflow.project.pause");
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 1, playpause, PendingIntent.FLAG_CANCEL_CURRENT);
Intent stop = new Intent();
stop.setAction("com.eciflow.project.stop");
PendingIntent stopI = PendingIntent.getBroadcast(getApplicationContext(), 1, stop, PendingIntent.FLAG_CANCEL_CURRENT);
remoteViews.setImageViewResource(R.id.playpause, R.drawable.pauseradio);
remoteViews.setImageViewResource(R.id.stop, R.drawable.stopradio);
remoteViews.setOnClickPendingIntent(R.id.playpause, pi);
remoteViews.setOnClickPendingIntent(R.id.stop, stopI);
remoteViews.setTextViewText(R.id.title, "Playing");
remoteViews.setTextViewText(R.id.text, param2);
remoteViews.setTextColor(R.id.title, getResources().getColor(android.R.color.holo_blue_dark));
remoteViews.setTextColor(R.id.text, getResources().getColor(android.R.color.holo_blue_dark));
startForeground(250, notification);
我正在播放流中的音乐......
为什么会发生这种情况?如果还有其他选择,我也愿意改变结构。
谢谢!
答案 0 :(得分:0)
设置标志时添加此代码:
notification.defaults | = Notification.DEFAULT_SOUND;
notification.defaults | = Notification.DEFAULT_VIBRATE;
notification.defaults | = Notification.DEFAULT_LIGHTS;
notification.flags | = Notification.FLAG_AUTO_CANCEL;