问题描述
搜索结果
我使用 AlarmManager()
火的通知。我将它设置在上午10:30上午和重复开火每24小时。
搜索结果
我的code是如下。我昨天已经测试,问题是,这是在刚刚在2个小时左右4-5次重复。我不理解这是什么问题。我只希望在10:30上午的射击,并在只有24小时重复。
搜索结果
请帮我解决这个问题。我打电话给我的应用程序的启动画面上的这个code 的onCreate()
搜索结果
我的code:
意图myIntent =新意图(Splash.this,AlarmReceiver.class);的PendingIntent的PendingIntent = PendingIntent.getBroadcast(Splash.this,
0,myIntent,0);AlarmManager alarmManager =(AlarmManager)getSystemService(ALARM_SERVICE);日历firingCal = Calendar.getInstance();
日历currentCal = Calendar.getInstance();firingCal.set(Calendar.HOUR_OF_DAY,10);
firingCal.set(Calendar.MINUTE,30);
firingCal.set(Calendar.SECOND,0);长intendedTime = firingCal.getTimeInMillis();
长currentTime的= currentCal.getTimeInMillis();如果(intendedTime> = currentTime的){
alarmManager.setRepeating(AlarmManager.RTC,intendedTime,
AlarmManager.INTERVAL_DAY,的PendingIntent);}其他{
firingCal.add(Calendar.DAY_OF_MONTH,1);
intendedTime = firingCal.getTimeInMillis(); alarmManager.setRepeating(AlarmManager.RTC,intendedTime,
AlarmManager.INTERVAL_DAY,的PendingIntent);
}
您可以使用CommonsWare 库。它有一个内置的支持,可以设定闹钟。
I am using AlarmManager()
to fire Notification. I am setting it to fire at 10:30 AM of the morning and repeat at every 24 hours.
My code is as follow. I have tested yesterday and the problem is that It was repeated around 4-5 times in just next 2 hours. I am not understanding that what is the problem. I want to fire it only at 10:30 AM of the morning and repeat at only 24 hours.
Please help me solve the problem. I am calling this code on my app's Splash screen onCreate()
My Code :
Intent myIntent = new Intent(Splash.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(Splash.this,
0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar firingCal = Calendar.getInstance();
Calendar currentCal = Calendar.getInstance();
firingCal.set(Calendar.HOUR_OF_DAY, 10);
firingCal.set(Calendar.MINUTE, 30);
firingCal.set(Calendar.SECOND, 0);
long intendedTime = firingCal.getTimeInMillis();
long currentTime = currentCal.getTimeInMillis();
if (intendedTime >= currentTime) {
alarmManager.setRepeating(AlarmManager.RTC, intendedTime,
AlarmManager.INTERVAL_DAY, pendingIntent);
} else {
firingCal.add(Calendar.DAY_OF_MONTH, 1);
intendedTime = firingCal.getTimeInMillis();
alarmManager.setRepeating(AlarmManager.RTC, intendedTime,
AlarmManager.INTERVAL_DAY, pendingIntent);
}
You can use CommonsWare cwac-wakeful library. It has an inbuilt support to set alarms.
这篇关于AlarmManager在每24小时触发通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!