gpt4 book ai didi

android - 关于Local notification的几个问题

转载 作者:行者123 更新时间:2023-11-30 00:12:04 24 4
gpt4 key购买 nike

我不是 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() 返回该日期对象的时间(以毫秒为单位)。

编辑

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

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);
}

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

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

关于android - 关于Local notification的几个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47995270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com