简体   繁体   English

Android通知在特定时间不会弹出

[英]Android Notification doesn't pop-up at given time

I just started working coverting my iOS app to Android. 我刚刚开始将iOS应用程序覆盖到Android。 But I'm having the following problem. 但是我有以下问题。

I created multiple classes so the alert pops-up. 我创建了多个类,因此弹出警报。 But the problem is that the alert pop-ups every 5/10 seconds instead of the given time. 但是问题是警报每5/10秒而不是给定时间弹出一次。 I know this has something to do with the following code: 我知道这与以下代码有关:

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime() + 5000, 10000, pendingIntent);

But the strangest thing is that the given time above that code doesn't trigger any thing: (Otherwise I could've just deleted the last line of code) 但是最奇怪的是,该代码上方的给定时间不会触发任何事件:(否则我可以删除最后一行代码)

private void setRecurringAlarm(Context context) {
    Calendar updateTime = Calendar.getInstance();
    updateTime.set(Calendar.HOUR_OF_DAY, 17);
    updateTime.set(Calendar.MINUTE, 18);

    Intent open = new Intent(this, AlarmReceiver.class);
    open.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, open, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarmManager = (AlarmManager) getSystemService(MyApp.ALARM_SERVICE);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime() + 5000, 10000, pendingIntent);

What's wrong with that code because the alarm doesn't pop-up at 17:18 but each time after 5 or 10 seconds. 该代码有什么问题,因为警报不会在17:18弹出,而是在5或10秒后每次弹出。 The service that i've created to display the notification doesn't start at 17:18 to display the message. 我创建的用于显示通知的服务不是从17:18开始以显示消息。 Does this has something to do with my timezone (Amsterdam Time)? 这与我的时区(阿姆斯特丹时间)有关吗?

I think you're passing in the wrong values for .setRepeating. 我认为您为.setRepeating传递了错误的值。 Have a look at the documentation 看一下文档

It looks to me like you're saying: broadcast for the first time 5 seconds from now, then every 10 seconds after that repeat 在我看来,您的意思是:从现在开始5秒钟进行第一次广播,然后重复播放每10秒钟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM