|
|
|
@ -13,9 +13,9 @@
|
|
|
|
|
* 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;
|
|
|
|
@ -23,21 +23,24 @@ 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,
|
|
|
|
|
NoteColumns.ALERTED_DATE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 列索引常量,用于从查询结果中提取数据
|
|
|
|
|
private static final int COLUMN_ID = 0;
|
|
|
|
|
private static final int COLUMN_ALERTED_DATE = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 接收广播时执行的方法,查询数据库并设置闹钟
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
long currentDate = System.currentTimeMillis();
|
|
|
|
@ -46,7 +49,7 @@ public class AlarmInitReceiver extends BroadcastReceiver {
|
|
|
|
|
NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,
|
|
|
|
|
new String[] { String.valueOf(currentDate) },
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (c != null) {
|
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
|
do {
|
|
|
|
@ -62,4 +65,4 @@ public class AlarmInitReceiver extends BroadcastReceiver {
|
|
|
|
|
c.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|