如何使用Android的报警管理器来设置多个闹钟 [英] how to set multiple alarms using android alarm manager

查看:150
本文介绍了如何使用Android的报警管理器来设置多个闹钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个报警application.I已经成功实施了基本的报警功能。

I'm building an alarm application.I have successfully implemented basic alarm functions.

Calendar calendar = Calendar.getInstance();
calendar.set(calendar.HOUR_OF_DAY, sHour);
calendar.set(calendar.MINUTE, sMin);
calendar.set(calendar.SECOND, 0);
calendar.set(calendar.MILLISECOND, 0);
long sdl = calendar.getTimeInMillis();

Intent intent = new Intent(AlarmList.this, AlarmReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(AlarmList.this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager ALARM1 = (AlarmManager)getSystemService(ALARM_SERVICE);
ALARM1.set(AlarmManager.RTC_WAKEUP, sdl, sender);

在我的应用程序,用户可以选择天(周日,周一...)重复报警每周一次。 我试图创建多个报警重复每周一次,但不知道该怎么做。 我可以创建使用(repeate)区间或者我应该创建多个报警经理吗?

in my application,user can select days(sunday,monday...) to repeat the alarm weekly. I'm trying to create multiple alarms to repeat weekly but don't know how to do it. can I create it using (repeate)interval or should I create multiple alarm managers?

推荐答案

您需要使用不同的广播ID的挂起的意图。就像是 这样的:

You need to use different Broadcast id's for the pending intents. Something like this:

    Intent intent = new Intent(load.this, AlarmReceiver.class);
    final int _id = (int) System.currentTimeMillis();
    PendingIntent appIntent = PendingIntent.getBroadcast(this, _id, intent,PendingIntent.FLAG_ONE_SHOT);

使用系统时间应为每未决的唯一标识符 意图你火。

Using the system time should be a unique identifier for every pending intent you fire.

这篇关于如何使用Android的报警管理器来设置多个闹钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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