Delete 'src_2F周希奥代码注释'

main
pstgu9p43 2 months ago
parent f488cd1d42
commit 8af6a49d79

@ -1,65 +0,0 @@
package net.micode.notes.ui;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
/**
* 这个类是一个广播接收器,用于初始化闹钟。
*/
public class AlarmInitReceiver extends BroadcastReceiver {
// 数据库查询的列
private static final String [] PROJECTION = new String [] {
NoteColumns.ID, // 标签ID
NoteColumns.ALERTED_DATE // 闹钟时间
};
// 对数据库的操作调用标签ID和闹钟时间
private static final int COLUMN_ID = 0;
private static final int COLUMN_ALERTED_DATE = 1;
/**
* 当接收到广播时,这个方法会被调用。
* @param context 上下文对象,用于访问应用程序的资源和类。
* @param intent 包含接收到的广播的Intent对象。
*/
@Override
public void onReceive(Context context, Intent intent) {
long currentDate = System.currentTimeMillis(); // 获取当前时间的毫秒值
// 查询数据库中未被提醒且类型为普通笔记的记录
Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,
new String[] { String.valueOf(currentDate) }, // 将当前时间转换为字符串作为查询参数
null);
// 如果查询结果不为空
if (c != null) {
if (c.moveToFirst()) { // 移动到查询结果的第一行
do {
// 获取闹钟时间
long alertDate = c.getLong(COLUMN_ALERTED_DATE);
// 创建一个Intent用于触发AlarmReceiver
Intent sender = new Intent(context, AlarmReceiver.class);
// 为Intent设置数据标识具体的笔记
sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID)));
// 创建PendingIntent用于AlarmManager触发时识别
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0);
// 获取AlarmManager实例
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// 设置闹钟使用RTC_WAKEUP模式确保设备在指定时间被唤醒
alarmManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);
} while (c.moveToNext()); // 移动到下一行,继续循环
}
c.close(); // 关闭Cursor
}
// 通过上述步骤,根据数据库里的闹钟时间创建闹钟机制
}
}
Loading…
Cancel
Save