You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
READMI/src/notes/ui/AlarmInitReceiver.java

66 lines
3.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (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
*
* 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;
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 [] {//声明PROJECTION每个元素包括id和提醒日期
NoteColumns.ID,
NoteColumns.ALERTED_DATE
};
private static final int COLUMN_ID = 0;
private static final int COLUMN_ALERTED_DATE = 1;//设定ID和闹钟信息的初始值
@Override
public void onReceive(Context context, Intent intent) {//接收广播后的处理过程
long currentDate = System.currentTimeMillis();//通过系统函数获了当前时间存入currentDate变量。
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);//类型转换将long类型的currentDate转变为String类
if (c != null) {
if (c.moveToFirst()) {//游标移动到开始位置
do {
long alertDate = c.getLong(COLUMN_ALERTED_DATE);//获取要提醒的日期
Intent sender = new Intent(context, AlarmReceiver.class);//新建一个intent类来指向alarmreceiver 来传输数据
sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID)));//设置数据为便签的uri和id
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0);//创建一个广播组件,可以在手机广播栏显示相应内容
AlarmManager alermManager = (AlarmManager) context//新建系统的闹钟服务
.getSystemService(Context.ALARM_SERVICE);
alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);//设置一系列需要传输的数据
} while (c.moveToNext());//游标移动到下一位置
}
c.close();//关闭游标
}
}
}