Search in sources :

Example 31 with AlarmManager

use of android.app.AlarmManager in project HomeMirror by HannahMitt.

the class AlarmReceiver method startMirrorUpdates.

public static void startMirrorUpdates(Context context) {
    AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReceiver.class);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, 0);
    alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + MINUTES_10, MINUTES_10, alarmIntent);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 32 with AlarmManager

use of android.app.AlarmManager in project Gadgetbridge by Freeyourgadget.

the class SleepAlarmWidget method setAlarmViaAlarmManager.

/**
     * Use the Android alarm manager to create the alarm icon in the status bar.
     *
     * @param packageContext {@code Context}: A Context of the application package implementing this
     *                       class.
     * @param triggerTime    {@code long}: time at which the underlying alarm is triggered in wall time
     *                       milliseconds since the epoch
     */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setAlarmViaAlarmManager(Context packageContext, long triggerTime) {
    AlarmManager am = (AlarmManager) packageContext.getSystemService(Context.ALARM_SERVICE);
    // TODO: launch the alarm configuration activity when clicking the alarm in the status bar
    Intent intent = new Intent(packageContext, ConfigureAlarms.class);
    PendingIntent pi = PendingIntent.getBroadcast(packageContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    am.setAlarmClock(new AlarmManager.AlarmClockInfo(triggerTime, pi), pi);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TargetApi(android.annotation.TargetApi)

Example 33 with AlarmManager

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

the class UrlManager method cancelClearNotificationAlarm.

private void cancelClearNotificationAlarm() {
    PendingIntent pendingIntent = createClearNotificationAlarmIntent();
    AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent)

Example 34 with AlarmManager

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

the class DaylightHeaderProvider method startAlarm.

private void startAlarm() {
    // TODO actually this should find out the next needed alarm
    // instead of forcing it every interval
    final Calendar c = Calendar.getInstance();
    final AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    if (mAlarmIntent != null) {
        alarmManager.cancel(mAlarmIntent);
    }
    Intent intent = new Intent(StatusBarHeaderMachine.STATUS_BAR_HEADER_UPDATE_ACTION);
    mAlarmIntent = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    // make sure hourly alarm is aligned with hour
    if (mAlarmIntervalMinutes == 0) {
        c.add(Calendar.HOUR_OF_DAY, 1);
        c.set(Calendar.MINUTE, 0);
    }
    long alarmStart = c.getTimeInMillis();
    long interval = mAlarmIntervalMinutes == 0 ? AlarmManager.INTERVAL_HOUR : mAlarmIntervalMinutes * 60 * 1000;
    alarmManager.setInexactRepeating(AlarmManager.RTC, alarmStart, interval, mAlarmIntent);
}
Also used : Calendar(java.util.Calendar) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 35 with AlarmManager

use of android.app.AlarmManager in project AdMoney by ErnestoGonAr.

the class AgregarNotf method agregarNotf.

public void agregarNotf(Context aContext, String nombre, float cantidad, String fecha, int frecuencia, int id) {
    java.util.Calendar calendar = java.util.Calendar.getInstance();
    String[] f = fecha.split("-");
    calendar.set(Calendar.MONTH, (Integer.parseInt(f[1]) - 1));
    calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(f[2]));
    calendar.set(Calendar.YEAR, Integer.parseInt(f[0]));
    calendar.set(Calendar.HOUR_OF_DAY, 18);
    calendar.set(Calendar.MINUTE, 2);
    calendar.set(Calendar.SECOND, 0);
    java.util.Calendar temp = java.util.Calendar.getInstance();
    if (calendar.before(temp)) {
        calendar = java.util.Calendar.getInstance();
        calendar.add(Calendar.MINUTE, 1);
    }
    Intent intent1 = new Intent(aContext, AlarmReceiver.class);
    intent1.putExtra("NotfNombre", nombre);
    intent1.putExtra("NotfCantidad", cantidad);
    intent1.putExtra("NotfFecha", fecha);
    intent1.putExtra("NotfFrecuencia", frecuencia);
    intent1.putExtra("NotfId", id);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(aContext, 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager am = (AlarmManager) aContext.getSystemService(aContext.ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
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