在按月设定Android报警 [英] Setting alarm on monthly basis android

查看:169
本文介绍了在按月设定Android报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的每天,每周,每月的基础设置报警的Andr​​oid应用程序。前两个是通过将给予日期和时间为milliseonds工作的罚款。但是,当我试图为做同样的月度这是行不通的。有完全不同的日期格式。

I am developing an android app for setting alarm on daily, weekly, monthly basis. The first two are working fine by converting the give date and time into milliseonds. But when I am trying to do the same for monthly it doesn't work. There is totally different date format.

我如下设置它,

Alarmtimefor30有以毫秒为单位指定的日期。

Alarmtimefor30 has the given date in milliseconds.

  am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTimefor30, 30*1440*60000 , pi);

我给intervalMillis为30 * 1440 * 60000这将导致以25.92亿即30天毫秒。当我尝试打印30 * 1440 * 60000它导致到1702967296.我不知道可能是什么问题。

I am giving intervalMillis as 30*1440*60000 which results to 2592000000 i.e 30 days in milliseconds. When I try to print 30*1440*60000 it results to 1702967296. I am not sure what could be the problem.

有另一种方式来设置每月报警?

Is there another way to set monthly alarm (to trigger on specific date and time every month)?

请帮助!谢谢!

推荐答案

默认情况下,一个整数文字在Java将是类型 INT ,这是一个32位数。当你乘一个 INT INT 的结果也是一个 INT ,所以你的结果被截断。显然,参数 setRepeating ,但这并不意味着编译器会解决这个问题你 - 你乘法仍将被截断。

By default, an integer literal in Java will be of type int, which is a 32-bit number. When you multiply an int by an int the result is also an int, so your result is being truncated. Obviously the argument to setRepeating is a long, but that doesn't mean the compiler will fix this for you - your multiplication will still be truncated.

解决方案是明确地强制文字是类型,这是一个64位的数字:

The solution is to explicitly force the literals to be of type long, which is a 64-bit number:

am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTimefor30, 30L*1440L*60000L , pi);

这篇关于在按月设定Android报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆