Android Open Source - android-for-dummies-v3 On Boot Receiver






From Project

Back to project page android-for-dummies-v3.

License

The source code is released under:

Apache License

If you think the Android project android-for-dummies-v3 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.dummies.tasks.receiver;
// w w  w  .  jav  a2 s.  co m
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;

import com.dummies.tasks.provider.TaskProvider;
import com.dummies.tasks.util.ReminderManager;

import java.util.Calendar;

/**
 * This class will be triggered when the phone first boots so that our
 * app can re-install any alarms that need to be set.  If we didn't do
 * this, then the phone would lose all of our alarms on reboot!
 */
public class OnBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        // Get the cursor for our tasks
        Cursor cursor = context.getContentResolver().query(
                TaskProvider.CONTENT_URI, null, null, null, null);

        // If our db is empty, don't do anything
        if (cursor == null)
            return;


        try {
            cursor.moveToFirst();

            // get the indices of the taskId and date_time columns
            int taskIdColumnIndex = cursor
                    .getColumnIndex(TaskProvider.COLUMN_TASKID);
            int dateTimeColumnIndex = cursor
                    .getColumnIndex(TaskProvider.COLUMN_DATE_TIME);
            int titleColumnIndex = cursor
                    .getColumnIndex(TaskProvider.COLUMN_TITLE);

            // Loop over all of the tasks in the db
            while (!cursor.isAfterLast()) {

                // Get the id and dateTime for this task
                long taskId = cursor.getLong(taskIdColumnIndex);
                long dateTime = cursor.getLong(dateTimeColumnIndex);
                String title = cursor.getString(titleColumnIndex);

                Calendar cal = Calendar.getInstance();
                cal.setTime(new java.util.Date(dateTime));

                // Set the reminder
                ReminderManager.setReminder(context, taskId,
                        title, cal);

                cursor.moveToNext();
            }

        } finally {
            // Always close the cursor when we finish!
            cursor.close();
        }
    }
}




Java Source Code List

com.dummies.helloandroid.ApplicationTest.java
com.dummies.helloandroid.MainActivity.java
com.dummies.silentmodetoggle.MainActivity.java
com.dummies.silentmodetoggle.util.RingerHelper.java
com.dummies.silentmodetoggle.widget.AppWidgetService.java
com.dummies.silentmodetoggle.widget.AppWidget.java
com.dummies.tasks.activity.PreferencesActivity.java
com.dummies.tasks.activity.TaskEditActivity.java
com.dummies.tasks.activity.TaskListActivity.java
com.dummies.tasks.adapter.TaskListAdapter.java
com.dummies.tasks.fragment.DatePickerDialogFragment.java
com.dummies.tasks.fragment.PreferencesFragment.java
com.dummies.tasks.fragment.TaskEditFragment.java
com.dummies.tasks.fragment.TaskListFragment.java
com.dummies.tasks.fragment.TimePickerDialogFragment.java
com.dummies.tasks.interfaces.OnEditFinished.java
com.dummies.tasks.interfaces.OnEditTask.java
com.dummies.tasks.provider.TaskProvider.java
com.dummies.tasks.receiver.OnAlarmReceiver.java
com.dummies.tasks.receiver.OnBootReceiver.java
com.dummies.tasks.tablet.activity.TaskListAndEditorActivity.java
com.dummies.tasks.util.ReminderManager.java