如何防止通知栏在通知操作单击时关闭 [英] How to prevent notification bar from closing upon notification action click
本文介绍了如何防止通知栏在通知操作单击时关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我有暂停/播放操作的通知,但是,当用户单击该操作时,通知栏正在关闭.如何防止通知栏在操作点击时关闭?
In my app i have notification with pause/play action, however, when user clicks on the action, notification bar is closing. How can i prevent notification bar from closing upon action click?
创建通知的方法:
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)
这篇关于如何防止通知栏在通知操作单击时关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文