【问题标题】:Scheduling local notification for a specific date and repeat yearly安排特定日期的本地通知并每年重复
【发布时间】:2021-02-24 21:43:50
【问题描述】:

我想在我的应用程序中使用本地通知,我想每年为用户发送生日消息。

1)我如何在特定日期和时间安排通知?这里使用 Display.getInstance().scheduleLocalNotification,我可以设置时间来安排通知,但我如何设置具体的日期和时间?

2) 有 REPEAT_NONE、分钟、小时、日、周,但是否也有 Repeat_Year?

3) localNotification 的覆盖方法是否有任何特定用途,即。本地通知接收()?我有 System.out 和 Dialog.show 方法,但是当通知出现时两者都不显示。

public class LocalNotificationTest implements LocalNotificationCallback {
    public void noti(){
        LocalNotification n = new LocalNotification();
        n.setAlertBody("body");
        n.setAlertTitle("title");
        n.setId("id");
        Display.getInstance().scheduleLocalNotification(n, System.currentTimeMillis() + 10 * 1000, LocalNotification.REPEAT_NONE);
    }

    @Override
    public void localNotificationReceived(String notificationId) {
         System.out.println("Received local notification "+notificationId+" in callback localNotificationReceived");
         Dialog.show("noti", "checking notifications", "ok", null);
    }

}

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    例如,您可以将重复设置为周,并在回调中递增一个计数器,直到您实际通知用户的第 52 次出现,而忽略前 51 个获取通知的实例。

    计数器值可以存储在 Preferences 中以进行持久化。

    【讨论】:

    • 这行不通,因为日期不会落在同一日期,因为 365 / 7 不是整数。它需要使用重复日才能工作,但我不确定为什么没有重复年。
    • 另外,您可以为未来所有年份设置 120 条通知,而不是重复
    • 谢谢你们俩.. localNotificationReceived() 方法的目的是什么,我里面有 Dialog.show() 但是当通知被触发时对话框不显示,这是为什么呢?
    • 在闰年使用重复日将被关闭,请确保您使用它来解释它们。
    • 您好,我还有一个问题。本地通知是否仅在应用程序在后台时才有效?如果应用程序关闭,它不会工作吗?我已经在设备中进行了测试,只有在应用最小化(在后台)时才会显示通知
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多