Search in sources :

Example 71 with AlarmManager

use of android.app.AlarmManager in project AlarmAndJob by dxsdyhm.

the class TostServiceHelper method initAlarmmager.

public static void initAlarmmager(Context context) {
    // 操作:发送一个广播,广播接收后Toast提示定时操作完成
    Intent intent = new Intent(context, AlarmRecive.class);
    intent.setAction("tost");
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
    // 开始时间
    long firstime = SystemClock.elapsedRealtime();
    AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    // 或者以下面方式简化
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstime, SCEDULE_TIME, sender);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 72 with AlarmManager

use of android.app.AlarmManager in project orgzly-android by orgzly.

the class ListWidgetProvider method scheduleUpdate.

private static void scheduleUpdate(Context context) {
    /*
         schedule updates via AlarmManager, because we don't want to wake the device on every update
         see https://developer.android.com/guide/topics/appwidgets/index.html#MetaData
         */
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent intent = getAlarmIntent(context);
    alarmManager.cancel(intent);
    /* repeat after every full hour because results of search can change on new day
            because of timezones repeat every hour instead of every day */
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.HOUR_OF_DAY, 1);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 1);
    alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, intent);
}
Also used : Calendar(java.util.Calendar) AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent)

Example 73 with AlarmManager

use of android.app.AlarmManager in project AndroidChromium by JackyAndroid.

the class ExponentialBackoffScheduler method createAlarm.

/**
 * Creates an alarm to fire the specified intent at the specified time.
 * @param intent The intent to fire.
 * @return the timestamp of the scheduled intent
 */
public long createAlarm(Intent intent, long timestamp) {
    PendingIntent retryPIntent = PendingIntent.getService(mContext, 0, intent, 0);
    AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    setAlarm(am, timestamp, retryPIntent);
    return timestamp;
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent)

Example 74 with AlarmManager

use of android.app.AlarmManager in project AndroidChromium by JackyAndroid.

the class OmahaClient method cancelRepeatingAlarm.

/**
 * Cancels the alarm that launches this service.  It will be replaced when Chrome next resumes.
 */
private void cancelRepeatingAlarm() {
    Intent requestIntent = createRegisterRequestIntent(this);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, requestIntent, PendingIntent.FLAG_NO_CREATE);
    // If the pendingIntent is null, it is likely that no alarm was created.
    if (pendingIntent != null) {
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        am.cancel(pendingIntent);
        pendingIntent.cancel();
    }
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 75 with AlarmManager

use of android.app.AlarmManager in project AndroidChromium by JackyAndroid.

the class OmahaClient method scheduleRepeatingAlarm.

/**
 * Sets a repeating alarm that fires request registration Intents.
 * Setting the alarm overwrites whatever alarm is already there, and rebooting
 * clears whatever alarms are currently set.
 */
private void scheduleRepeatingAlarm() {
    Intent registerIntent = createRegisterRequestIntent(this);
    PendingIntent pIntent = PendingIntent.getService(this, 0, registerIntent, 0);
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    setAlarm(am, pIntent, AlarmManager.RTC, mTimestampForNewRequest);
}
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