android闹钟响起事件可以监听到吗,应该怎么用
2016-05-02 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517193
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
类似以下method中的写法
<pre class="brush:java; toolbar: true; auto-links: false;">// Schedule timer task within Alarm
private void scheduleTask(Message message) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, whenMap.get("year"));
calendar.set(Calendar.MONTH, whenMap.get("month"));
calendar.set(Calendar.DAY_OF_MONTH, whenMap.get("day"));
calendar.set(Calendar.HOUR_OF_DAY, whenMap.get("hour"));
calendar.set(Calendar.MINUTE, whenMap.get("min"));
calendar.set(Calendar.SECOND, whenMap.get("sec"));
Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra("textContact", message.getTextContact().trim());
intent.putExtra("textWhen", message.getTextWhen());
intent.putExtra("textContent", message.getTextContent());
// Different requestCode can lead to different PendingIntent
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
(int) calendar.getTimeInMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>();
// AlarmManager.RTC_WAKEUP can be executed when CPU sleep
// AlarmManager.RTC can't be executed when CPU sleep
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}</pre>
<br>
<pre class="brush:java; toolbar: true; auto-links: false;">// Schedule timer task within Alarm
private void scheduleTask(Message message) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, whenMap.get("year"));
calendar.set(Calendar.MONTH, whenMap.get("month"));
calendar.set(Calendar.DAY_OF_MONTH, whenMap.get("day"));
calendar.set(Calendar.HOUR_OF_DAY, whenMap.get("hour"));
calendar.set(Calendar.MINUTE, whenMap.get("min"));
calendar.set(Calendar.SECOND, whenMap.get("sec"));
Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra("textContact", message.getTextContact().trim());
intent.putExtra("textWhen", message.getTextWhen());
intent.putExtra("textContent", message.getTextContent());
// Different requestCode can lead to different PendingIntent
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
(int) calendar.getTimeInMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>();
// AlarmManager.RTC_WAKEUP can be executed when CPU sleep
// AlarmManager.RTC can't be executed when CPU sleep
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}</pre>
<br>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询