关于Local notification的几个问题

Several questions about Local notification

我不是 Codename One 的新用户,但这是我第一次在这个框架中使用本地通知。在我的应用程序中,我有一个选择器允许用户选择时间(小时和分钟)。我收到了使用 getTime() 方法选择的时间。现在我希望我的本地通知在那个时候触发。我需要在 Display.getInstance().scheduleLocalNotification() 函数的第二个参数中给出的正确值是多少?

到目前为止,我只有这个示例,但我不明白如何将它应用到我的需要中:

Display.getInstance().scheduleLocalNotification(notification, System.currentTimeMillis() + 10 * 1000, LocalNotification.REPEAT_NONE);

来自该方法的 Java 文档

@param firstTime time in milliseconds when to schedule the notification @param repeat repeat one of the following: REPEAT_NONE, REPEAT_FIFTEEN_MINUTES, REPEAT_HALF_HOUR, REPEAT_HOUR, REPEAT_DAY, REPEAT_WEEK

因此您可以使用 Date 对象方法 getTime() return 该日期对象的时间(以毫秒为单位)。

编辑

我们假设这是您的时间选择器的回调

public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
    Calendar date = Calendar.getInstance(); // This is the time now, so the day is set to today
    date.set(Calendar.HOUR_OF_DAY, hourOfDay);
    date.set(Calendar.MINUTE, minute);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.MILLISECOND, 0);
    Display.scheduleLocalNotification(LocalNotification, date.getTime().getTime(), repeat);
}

设置秒和毫秒只是为了确保闹钟在用户选择的确切分钟响起。

您也可以像我们更改小时和分钟一样更改日、月和年。