Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于修改系统时间,闹钟不正确的问题 #1

Open
lxn348567248 opened this issue May 31, 2016 · 3 comments
Open

关于修改系统时间,闹钟不正确的问题 #1

lxn348567248 opened this issue May 31, 2016 · 3 comments

Comments

@lxn348567248
Copy link

lxn348567248 commented May 31, 2016

因为前段时间,也做了个闹钟的功能,也遇到了这些问题,也是这样搞定的。
如果用户,修改了系统的时间,如果我们设置之前就设置一个时间,那么就会触发这个过期闹钟任务。
我的解决方案如下:
    在我们触发的Receive中,加一个时间差的比较:
    代码如下:
    private final static int STALE_WINDOW = 60;//60秒
long now = System.currentTimeMillis();
  if (intent.hasExtra("time")) {
  long sendTime = intent.getLongExtra("time", -1);//闹钟触发的时间
  if (now > sendTime + STALE_WINDOW * 1000) {
  return;
  }

还有一个是如果用户修改系统的时间,我们应试在清单中注册一下几个广播,得新设置一个闹钟。

"ANDROID.INTENT.ACTION.BOOT_COMPLETED"
"android.intent.action.TIME_SET"
"ANDROID.INTENT.ACTION.TIME_TICK"
"ANDROID.INTENT.ACTION.TIMEZONE_CHANGED"

@houxiaodong
Copy link

你好,进程被杀死后,你是怎么解决的呢?还有就是如果是设置每天重复响闹钟,我们怎么获取到闹钟响的时刻呢?

@pahoehoe
Copy link

@loonggg
刚试了下。在小米4c上开启自启动权限。退出app以后还能收到onReceive()回调。在android studio 2.1自带的模拟器上(api 19)什么都不用设置,退出app后也能收到onReceive()回调。
@houxiaodong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants