gpt4 book ai didi

java - 滑动关闭通知不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 12:44:19 25 4
gpt4 key购买 nike

我尝试通过滑动关闭通知,但它就是无法关闭。我尝试设置正确的标志并将 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);

我正在播放流中的背景音乐...

有什么想法为什么会发生这种情况吗?如果有其他选择,我也愿意改变结构。

谢谢!

最佳答案

在设置标志时添加此代码:
notification.defaults |= notification.DEFAULT_SOUND; notification.defaults |= notification.DEFAULT_VIBRATE; notification.defaults |= notification.DEFAULT_LIGHTS; notification.flags |= notification.FLAG_AUTO_CANCEL;

关于java - 滑动关闭通知不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36491355/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com