|
|
|
@ -1,17 +1,15 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
|
* 版权所有 (c) 2010-2011, MiCode 开源社区 (www.micode.net)
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
* 本文件授权使用 Apache License, Version 2.0(以下简称“许可证”);
|
|
|
|
|
* 除非符合许可证规定,否则不得使用此文件。
|
|
|
|
|
* 您可以从以下网址获取许可证副本:
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
* 除非适用法律要求或书面同意,否则根据许可证分发的软件
|
|
|
|
|
* 均按“原样”分发,不附带任何明示或暗示的保证或条件。
|
|
|
|
|
* 有关许可权限和限制的具体语言,请参阅许可证。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
@ -27,18 +25,21 @@ import android.database.Cursor;
|
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* AlarmInitReceiver 类用于初始化闹钟提醒。
|
|
|
|
|
* 当设备启动或应用安装/更新后,该接收器会被触发,用于设置未来的闹钟提醒。
|
|
|
|
|
*/
|
|
|
|
|
public class AlarmInitReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
// 定义查询数据库时要获取的列
|
|
|
|
|
private static final String [] PROJECTION = new String [] {
|
|
|
|
|
private static final String[] PROJECTION = new String[]{
|
|
|
|
|
NoteColumns.ID, // 笔记的ID
|
|
|
|
|
NoteColumns.ALERTED_DATE // 笔记的提醒日期
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 定义列的索引,以便在Cursor中快速访问
|
|
|
|
|
private static final int COLUMN_ID = 0;
|
|
|
|
|
private static final int COLUMN_ALERTED_DATE = 1;
|
|
|
|
|
private static final int COLUMN_ID = 0;
|
|
|
|
|
private static final int COLUMN_ALERTED_DATE = 1;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
@ -51,7 +52,7 @@ public class AlarmInitReceiver extends BroadcastReceiver {
|
|
|
|
|
Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
|
|
|
|
|
PROJECTION,
|
|
|
|
|
NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,
|
|
|
|
|
new String[] { String.valueOf(currentDate) }, // 查询参数,这里只有当前日期
|
|
|
|
|
new String[]{String.valueOf(currentDate)}, // 查询参数,这里只有当前日期
|
|
|
|
|
null); // 不需要排序
|
|
|
|
|
|
|
|
|
|
// 检查Cursor是否为null
|
|
|
|
@ -74,11 +75,11 @@ public class AlarmInitReceiver extends BroadcastReceiver {
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0);
|
|
|
|
|
|
|
|
|
|
// 获取AlarmManager服务
|
|
|
|
|
AlarmManager alermManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
|
|
|
|
|
|
|
|
// 设置一个闹钟,当到达提醒日期时,触发PendingIntent(即发送广播给AlarmReceiver)
|
|
|
|
|
// AlarmManager.RTC_WAKEUP表示在指定时间唤醒设备并发送广播
|
|
|
|
|
alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);
|
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);
|
|
|
|
|
|
|
|
|
|
} while (c.moveToNext()); // 移动到下一条记录,继续循环
|
|
|
|
|
}
|
|
|
|
|