Example usage for android.content Intent ACTION_PROVIDER_CHANGED

List of usage examples for android.content Intent ACTION_PROVIDER_CHANGED

Introduction

In this page you can find the example usage for android.content Intent ACTION_PROVIDER_CHANGED.

Prototype

String ACTION_PROVIDER_CHANGED

To view the source code for android.content Intent ACTION_PROVIDER_CHANGED.

Click Source Link

Document

Broadcast Action: Some content providers have parts of their namespace where they publish new events or items that the user may be especially interested in.

Usage

From source file:com.android.calendar.alerts.AlertService.java

void processMessage(Message msg) {
    Bundle bundle = (Bundle) msg.obj;//from  www  . ja v  a2  s. c  o m

    // On reboot, update the notification bar with the contents of the
    // CalendarAlerts table.
    String action = bundle.getString("action");
    if (DEBUG) {
        Log.d(TAG, bundle.getLong(android.provider.CalendarContract.CalendarAlerts.ALARM_TIME) + " Action = "
                + action);
    }

    // Some OEMs had changed the provider's EVENT_REMINDER broadcast to their own event,
    // which broke our unbundled app's reminders.  So we added backup alarm scheduling to the
    // app, but we know we can turn it off if we ever receive the EVENT_REMINDER broadcast.
    boolean providerReminder = action.equals(android.provider.CalendarContract.ACTION_EVENT_REMINDER);
    if (providerReminder) {
        if (sReceivedProviderReminderBroadcast == null) {
            sReceivedProviderReminderBroadcast = Utils.getSharedPreference(this, PROVIDER_REMINDER_PREF_KEY,
                    false);
        }

        if (!sReceivedProviderReminderBroadcast) {
            sReceivedProviderReminderBroadcast = true;
            Log.d(TAG, "Setting key " + PROVIDER_REMINDER_PREF_KEY + " to: true");
            Utils.setSharedPreference(this, PROVIDER_REMINDER_PREF_KEY, true);
        }
    }

    if (providerReminder || action.equals(Intent.ACTION_PROVIDER_CHANGED)
            || action.equals(android.provider.CalendarContract.ACTION_EVENT_REMINDER)
            || action.equals(AlertReceiver.EVENT_REMINDER_APP_ACTION)
            || action.equals(Intent.ACTION_LOCALE_CHANGED)) {

        // b/7652098: Add a delay after the provider-changed event before refreshing
        // notifications to help issue with the unbundled app installed on HTC having
        // stale notifications.
        if (action.equals(Intent.ACTION_PROVIDER_CHANGED)) {
            try {
                Thread.sleep(5000);
            } catch (Exception e) {
                // Ignore.
            }
        }

        updateAlertNotification(this);
    } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
        // The provider usually initiates this setting up of alarms on startup,
        // but there was a bug (b/7221716) where a race condition caused this step to be
        // skipped, resulting in missed alarms.  This is a stopgap to minimize this bug
        // for devices that don't have the provider fix, by initiating this a 2nd time here.
        // However, it would still theoretically be possible to hit the race condition
        // the 2nd time and still miss alarms.
        //
        // TODO: Remove this when the provider fix is rolled out everywhere.
        Intent intent = new Intent();
        intent.setClass(this, InitAlarmsService.class);
        startService(intent);
    } else if (action.equals(Intent.ACTION_TIME_CHANGED)) {
        doTimeChanged();
    } else if (action.equals(AlertReceiver.ACTION_DISMISS_OLD_REMINDERS)) {
        dismissOldAlerts(this);
    } else {
        Log.w(TAG, "Invalid action: " + action);
    }

    // Schedule the alarm for the next upcoming reminder, if not done by the provider.
    if (sReceivedProviderReminderBroadcast == null || !sReceivedProviderReminderBroadcast) {
        Log.d(TAG, "Scheduling next alarm with AlarmScheduler. " + "sEventReminderReceived: "
                + sReceivedProviderReminderBroadcast);
        AlarmScheduler.scheduleNextAlarm(this);
    }
}