gpt4 book ai didi

android - 如何防止通知栏在通知操作单击时关闭

转载 作者:行者123 更新时间:2023-11-29 19:26:38 26 4
gpt4 key购买 nike

在我的应用程序中,我收到带有暂停/播放操作的通知,但是,当用户单击该操作时,通知栏将关闭。如何防止通知栏在点击操作时关闭?

创建通知的方法:

public void createNotification() {
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);

Intent intent2 = new Intent(this, IntentActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
pIntent2 = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent2, 0);

builder = new NotificationCompat.Builder(context);
Notification noti = builder
.setAutoCancel(true)
.setContentTitle("Title")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setPriority(Notification.PRIORITY_MAX)
.setStyle(new NotificationCompat.BigTextStyle().bigText("Czas trwania: " + time + "\nKalorie: 4kcal"))
.addAction(icon, actionString, pIntent2).build();

notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
}

最佳答案

更改您的代码

setAutoCancel(true)

setAutoCancel(false)

关于android - 如何防止通知栏在通知操作单击时关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41238380/

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