在呼叫接收器上清除呼叫通知

时间:2014-12-30 13:48:29

标签: java android

我有一个接听来电,我希望在收到广播时清除通话通知,我该怎么办?

public class IncommingCallReceiver extends BroadcastReceiver
{
    public void onReceive(final Context context, final Intent intent) 
    {
        //some method
    }
}

1 个答案:

答案 0 :(得分:1)

使用ID

取消通知
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 
notificationManager.cancel(id);

创建通知时创建ID

  // Sets an ID for the notification
    int mNotificationId = 001;
    // Gets an instance of the NotificationManager service
    NotificationManager mNotifyMgr = 
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
    mNotifyMgr.notify(mNotificationId, mBuilder.build());

参考here