Search in sources :

Example 6 with AlarmManager

use of android.app.AlarmManager in project AndroidTraining by mixi-inc.

the class DefaultModule method configure.

@SuppressWarnings("unchecked")
protected void configure() {
    bind(Application.class).toProvider(ApplicationProvider.class).in(ApplicationScoped.class);
    bind(Context.class).toProvider(ContextProvider.class);
    bind(Handler.class).toProvider(HandlerProvider.class).in(ApplicationScoped.class);
    bind(ActivityManager.class).toProvider(new SystemServiceProvider<ActivityManager>(Context.ACTIVITY_SERVICE));
    bind(AlarmManager.class).toProvider(new SystemServiceProvider<AlarmManager>(Context.ALARM_SERVICE));
    bind(AudioManager.class).toProvider(new SystemServiceProvider<AudioManager>(Context.AUDIO_SERVICE));
    bind(ConnectivityManager.class).toProvider(new SystemServiceProvider<ConnectivityManager>(Context.CONNECTIVITY_SERVICE));
    bind(InputMethodManager.class).toProvider(new SystemServiceProvider<InputMethodManager>(Context.INPUT_METHOD_SERVICE));
    bind(KeyguardManager.class).toProvider(new SystemServiceProvider<KeyguardManager>(Context.KEYGUARD_SERVICE));
    bind(LocationManager.class).toProvider(new SystemServiceProvider<LocationManager>(Context.LOCATION_SERVICE));
    bind(NotificationManager.class).toProvider(new SystemServiceProvider<NotificationManager>(Context.NOTIFICATION_SERVICE));
    bind(PowerManager.class).toProvider(new SystemServiceProvider<PowerManager>(Context.POWER_SERVICE));
    bind(SensorManager.class).toProvider(new SystemServiceProvider<SensorManager>(Context.SENSOR_SERVICE));
    bind(TelephonyManager.class).toProvider(new SystemServiceProvider<TelephonyManager>(Context.TELEPHONY_SERVICE));
    bind(Vibrator.class).toProvider(new SystemServiceProvider<Vibrator>(Context.VIBRATOR_SERVICE));
    bind(WifiManager.class).toProvider(new SystemServiceProvider<WifiManager>(Context.WIFI_SERVICE));
    bind(WindowManager.class).toProvider(new SystemServiceProvider<WindowManager>(Context.WINDOW_SERVICE));
    bind(mAccountManagerClass).toProvider(AccountManagerProvider.class);
    bind(ObserverManager.class);
    bindProviderListener(new ObserverRegister());
    bind(StateManager.class).in(ApplicationScoped.class);
    bind(StateEventObserver.class);
    bindFieldListener(RetainState.class, new RetainStateListener());
}
Also used : WifiManager(android.net.wifi.WifiManager) ConnectivityManager(android.net.ConnectivityManager) InputMethodManager(android.view.inputmethod.InputMethodManager) ActivityManager(android.app.ActivityManager) WindowManager(android.view.WindowManager) PowerManager(android.os.PowerManager) AudioManager(android.media.AudioManager) StateManager(proton.inject.state.StateManager) TelephonyManager(android.telephony.TelephonyManager) Context(android.content.Context) LocationManager(android.location.LocationManager) ApplicationProvider(proton.inject.provider.ApplicationProvider) NotificationManager(android.app.NotificationManager) HandlerProvider(proton.inject.provider.HandlerProvider) RetainStateListener(proton.inject.state.RetainStateListener) SensorManager(android.hardware.SensorManager) AlarmManager(android.app.AlarmManager) Vibrator(android.os.Vibrator) KeyguardManager(android.app.KeyguardManager) ObserverRegister(proton.inject.observer.ObserverRegister)

Example 7 with AlarmManager

use of android.app.AlarmManager in project qksms by moezbhatti.

the class RetryScheduler method setRetryAlarm.

public static void setRetryAlarm(Context context) {
    Cursor cursor = PduPersister.getPduPersister(context).getPendingMessages(Long.MAX_VALUE);
    if (cursor != null) {
        try {
            if (cursor.moveToFirst()) {
                // The result of getPendingMessages() is order by due time.
                long retryAt = cursor.getLong(cursor.getColumnIndexOrThrow(PendingMessages.DUE_TIME));
                Intent service = new Intent(TransactionService.HANDLE_PENDING_TRANSACTIONS_ACTION, null, context, TransactionService.class);
                PendingIntent operation = PendingIntent.getService(context, 0, service, PendingIntent.FLAG_ONE_SHOT);
                AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                am.set(AlarmManager.RTC, retryAt, operation);
                if (LOCAL_LOGV)
                    Log.v(TAG, "Next retry is scheduled at " + (retryAt - System.currentTimeMillis()) + "ms from now");
            }
        } finally {
            cursor.close();
        }
    }
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Cursor(android.database.Cursor)

Example 8 with AlarmManager

use of android.app.AlarmManager in project qksms by moezbhatti.

the class SettingsFragment method updateAlarmManager.

public static void updateAlarmManager(Context context, boolean enabled) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("H:mm");
    Calendar calendar = Calendar.getInstance();
    Calendar dayCalendar = Calendar.getInstance();
    dayCalendar.setTimeInMillis(System.currentTimeMillis());
    try {
        calendar.setTime(simpleDateFormat.parse(PreferenceManager.getDefaultSharedPreferences(context).getString(DAY_START, "6:00")));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    dayCalendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
    dayCalendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE));
    Intent day = new Intent(context, NightModeAutoReceiver.class);
    PendingIntent dayIntent = PendingIntent.getBroadcast(context, 0, day, 0);
    Calendar nightCalendar = Calendar.getInstance();
    nightCalendar.setTimeInMillis(System.currentTimeMillis());
    try {
        calendar.setTime(simpleDateFormat.parse(PreferenceManager.getDefaultSharedPreferences(context).getString(NIGHT_START, "21:00")));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    nightCalendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
    nightCalendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE));
    Intent night = new Intent(context, NightModeAutoReceiver.class);
    PendingIntent nightIntent = PendingIntent.getBroadcast(context, 1, night, 0);
    context.sendBroadcast(night);
    if (enabled) {
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, dayCalendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, dayIntent);
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, nightCalendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, nightIntent);
    } else {
        alarmManager.cancel(dayIntent);
        alarmManager.cancel(nightIntent);
    }
}
Also used : Calendar(java.util.Calendar) AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ParseException(java.text.ParseException) PendingIntent(android.app.PendingIntent) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with AlarmManager

use of android.app.AlarmManager in project Signal-Android by WhisperSystems.

the class MessageNotifier method clearReminder.

public static void clearReminder(Context context) {
    Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 10 with AlarmManager

use of android.app.AlarmManager in project Signal-Android by WhisperSystems.

the class KeyCachingService method startTimeoutIfAppropriate.

private void startTimeoutIfAppropriate() {
    boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(this);
    if ((activitiesRunning == 0) && (KeyCachingService.masterSecret != null) && timeoutEnabled && !TextSecurePreferences.isPasswordDisabled(this)) {
        long timeoutMinutes = TextSecurePreferences.getPassphraseTimeoutInterval(this);
        long timeoutMillis = TimeUnit.MINUTES.toMillis(timeoutMinutes);
        Log.w("KeyCachingService", "Starting timeout: " + timeoutMillis);
        AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE);
        alarmManager.cancel(pending);
        alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + timeoutMillis, pending);
    }
}
Also used : AlarmManager(android.app.AlarmManager)

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