Android的取消通知通知、Android

2023-09-06 13:16:40 作者:海是倒过来的天

我有一个后台运行的服务来获得数据。我检查了新的数据和发送状态栏通知。发送通知是服务的一部分。当用户看到该通知,他登录到应用程序,并接受它。那个时候我想从状态栏中删除。我能做到这一点?

解决方案

 如果(Context.NOTIFICATION_SERVICE!= NULL){
        字符串NS = Context.NOTIFICATION_SERVICE;
        NotificationManager nMgr =(NotificationManager)getApplicationContext()getSystemService(NS)。
        nMgr.cancel(0);
    }
 

上面写的code在第二类和使用id 0创建一流的通知。

I have a background service running to get data. I check for new data and send status bar notification. Sending notification is part of the service. When user sees that notification, he logs on to the application and accepts it. That time I want to delete it from status bar. Can I do that ?

解决方案 Android 7.0截图曝光 缺少层次感

if (Context.NOTIFICATION_SERVICE!=null) {
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(ns);
        nMgr.cancel(0);
    }

write the above code in the second class and create the notifications in the first class using the id 0.