在扑中如何清除通知栏? [英] In flutter how to clear notification in bar?
问题描述
我正在学习Google云消息传递,并且 firebase消息传递可以正常工作,但是当用户不这样做时单击通知以打开应用程序,而是通过手动打开并进入前台直接进入应用程序,通知保持不变.我希望与应用相关的那些通知消息在应用进入前台时消失.我该如何实现?
I am learning Google cloud messaging and firebase messaging is working fine, but when a user do not click at the notification to open the app and instead goes directly to app by manually opening it and bringing to foreground, the notification stays. I want those notification message related to my app go away when the app comes to foreground. How can I achieve this ?
推荐答案
它认为在文档.
但是您可以尝试一下.您只需转到Android文件夹中的MainActivity.java,并做这样的事情.
But you can try this. You can just go to your MainActivity.java in your Android folder, and do something like this.
import android.app.NotificationManager;
import android.content.Context;
导入这些软件包.
Import these packages.
@Override
protected void onResume() {
super.onResume();
// Removing All Notifications
closeAllNotifications();
}
private void closeAllNotifications() {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
在MainActivity.java的 onCreate
下添加 onResume
函数.
希望这能解决您的问题.
Add an onResume
function below onCreate
on MainActivity.java.
Hope this solves your issue.
这篇关于在扑中如何清除通知栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!