Android取消通知

use*_*844 7 android

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

sar*_*ath 18

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

在第二个类中编写上面的代码,并使用id 0在第一个类中创建通知.