Update AlarmInitReceiver.java

main
pf45q8f3g 7 months ago
parent 7db4521cd4
commit e74509c1ce

@ -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()); // 移动到下一条记录,继续循环
}

Loading…
Cancel
Save