Search in sources :

Example 16 with AlarmManager

use of android.app.AlarmManager in project remusic by aa112901.

the class MediaService method timing.

public void timing(int time) {
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(PAUSE_ACTION), PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC, System.currentTimeMillis() + time, pendingIntent);
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 17 with AlarmManager

use of android.app.AlarmManager in project Reader by TheKeeperOfPie.

the class Receiver method setAlarm.

public static void setAlarm(Context context) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    Intent intentInbox = new Intent(INTENT_INBOX);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentInbox, PendingIntent.FLAG_UPDATE_CURRENT);
    long interval = Long.parseLong(preferences.getString(AppSettings.PREF_INBOX_CHECK_INTERVAL, "1800000"));
    if (interval > 0) {
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, interval, pendingIntent);
    }
    Log.d(TAG, "setAlarm: " + interval);
}
Also used : SharedPreferences(android.content.SharedPreferences) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 18 with AlarmManager

use of android.app.AlarmManager in project SeriesGuide by UweTrottmann.

the class ListWidgetProvider method onUpdate.

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // update all added list widgets
    for (int appWidgetId : appWidgetIds) {
        onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, null);
    }
    // set an alarm to update widgets every x mins if the device is awake
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (am != null) {
        PendingIntent pi = getUpdatePendingIntent(context);
        am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + REPETITION_INTERVAL, REPETITION_INTERVAL, pi);
        Timber.d("onUpdate: scheduled widget UPDATE alarm.");
    }
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent)

Example 19 with AlarmManager

use of android.app.AlarmManager in project SeriesGuide by UweTrottmann.

the class ListWidgetProvider method onDisabled.

@Override
public void onDisabled(Context context) {
    // remove the update alarm if the last widget is gone
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (am != null) {
        PendingIntent pi = getUpdatePendingIntent(context);
        am.cancel(pi);
        Timber.d("onDisabled: canceled widget UPDATE alarm.");
    }
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent)

Example 20 with AlarmManager

use of android.app.AlarmManager in project android_frameworks_base by ResurrectionRemix.

the class BluetoothDiscoverableTimeoutReceiver method setDiscoverableAlarm.

public static void setDiscoverableAlarm(Context context, long alarmTime) {
    Log.d(TAG, "setDiscoverableAlarm(): alarmTime = " + alarmTime);
    Intent intent = new Intent(INTENT_DISCOVERABLE_TIMEOUT);
    intent.setClass(context, BluetoothDiscoverableTimeoutReceiver.class);
    PendingIntent pending = PendingIntent.getBroadcast(context, 0, intent, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (pending != null) {
        // Cancel any previous alarms that do the same thing.
        alarmManager.cancel(pending);
        Log.d(TAG, "setDiscoverableAlarm(): cancel prev alarm");
    }
    pending = PendingIntent.getBroadcast(context, 0, intent, 0);
    alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pending);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

AlarmManager (android.app.AlarmManager)471 PendingIntent (android.app.PendingIntent)349 Intent (android.content.Intent)323 Calendar (java.util.Calendar)75 SuppressLint (android.annotation.SuppressLint)24 Date (java.util.Date)24 Context (android.content.Context)22 SharedPreferences (android.content.SharedPreferences)20 SimpleDateFormat (java.text.SimpleDateFormat)18 Test (org.junit.Test)17 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)13 Config (org.robolectric.annotation.Config)13 Handler (android.os.Handler)11 HashMap (java.util.HashMap)11 PowerManager (android.os.PowerManager)10 File (java.io.File)10 Map (java.util.Map)10 Activity (android.app.Activity)9 ShadowAlarmManager (org.robolectric.shadows.ShadowAlarmManager)9 TargetApi (android.annotation.TargetApi)8