以编程方式取消本地通知

时间:2016-02-07 15:18:22

标签: codenameone

这是在android上。我正在创建如下的本地通知:

public final static String ONGOING_CALL = "ONGOING_CALL";

 public static void displayOngoingCallNotification(String calleeNames,String msg) {
        try {
            LocalNotification n = new LocalNotification();
            n.setId(ONGOING_CALL);
            n.setAlertBody(msg);

            n.setAlertTitle("Calling "+calleeNames);

            Display.getInstance().scheduleLocalNotification(
                    n,
                    System.currentTimeMillis() + 500, // fire date/time
                    LocalNotification.REPEAT_NONE // Whether to repeat and what frequency
            );
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

稍后以编程方式取消:

public static void dismissOngoingCallNotification() {

        try {
            System.out.println("Going to dismiss ongoing call");
            Display.getInstance().cancelLocalNotification(ONGOING_CALL);
            System.out.println("ongoing call dismissed");

        } catch (Exception ex) {
            System.out.println("Trouble, can't dismiss ongoing call");

            ex.printStackTrace();
        }

    }

然而,在我手动点击之前,通知仍然存在。我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

Local notifications是定时事件,在这种情况下,定时事件在已经发生后被取消。我不认为我们在新的通知框架中有办法删除已经过去的通知的视觉通知。