Example usage for android.content Context ALARM_SERVICE

List of usage examples for android.content Context ALARM_SERVICE

Introduction

In this page you can find the example usage for android.content Context ALARM_SERVICE.

Prototype

String ALARM_SERVICE

To view the source code for android.content Context ALARM_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.AlarmManager for receiving intents at a time of your choosing.

Usage

From source file:com.near.chimerarevo.fragments.SettingsFragment.java

private void setAlarm(int sel, boolean isEnabled) {
    Intent intent = new Intent(getActivity().getApplicationContext(), NewsService.class);
    PendingIntent pintent = PendingIntent.getService(getActivity().getApplicationContext(), 0, intent, 0);
    AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);

    alarm.cancel(pintent);//w w  w  . j  av a2s  . c  om

    if (isEnabled) {
        long delay;
        switch (sel) {
        case 0:
            delay = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
            break;
        case 1:
            delay = AlarmManager.INTERVAL_HALF_HOUR;
            break;
        case 2:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        case 3:
            delay = 2 * AlarmManager.INTERVAL_HOUR;
            break;
        case 4:
            delay = 3 * AlarmManager.INTERVAL_HOUR;
            break;
        case 5:
            delay = 6 * AlarmManager.INTERVAL_HOUR;
            break;
        case 6:
            delay = AlarmManager.INTERVAL_HALF_DAY;
            break;
        case 7:
            delay = AlarmManager.INTERVAL_DAY;
            break;
        default:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        }

        alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.uptimeMillis(), delay, pintent);
    }
}

From source file:de.hero.vertretungsplan.MainActivity.java

public static void setNewAlarm(Context context, boolean set, String interval) {
    Intent i = new Intent(context, de.hero.vertretungsplan.CheckForUpdates.class);
    PendingIntent pi = PendingIntent.getService(context, 0, i, 0);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    am.cancel(pi); // cancel any existing alarms
    Log.d("MainActivity", "cancelAlarm");
    if (set) {// ww  w  . ja  va2  s  . co  m

        long lngInterval;
        switch (interval) {
        case "1/2":
            lngInterval = AlarmManager.INTERVAL_HALF_HOUR;
            break;
        case "1":
            lngInterval = AlarmManager.INTERVAL_HOUR;
            break;
        case "6":
            lngInterval = AlarmManager.INTERVAL_HALF_DAY / 2;
            break;
        case "3":
        default:
            lngInterval = AlarmManager.INTERVAL_HOUR * 3;
            break;
        }
        Log.d("MainActivity", "setAlarm " + interval + " Stunden");
        am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR / 3, lngInterval, pi);
        // For debugging after 10 seconds
        // am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
        // SystemClock.elapsedRealtime() + 25000 ,
        // AlarmManager.INTERVAL_HOUR , pi);

    }
}

From source file:com.lloydtorres.stately.push.TrixHelper.java

/**
 * Cancels any previous alarms set for Alphys.
 * @param c App context.//w  w w.  j a v  a2s  . c  o m
 */
public static void stopAlarmForAlphys(Context c) {
    Intent alphysIntent = new Intent(c, AlphysService.class);
    PendingIntent pendingIntent = PendingIntent.getService(c, 0, alphysIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pendingIntent);
}

From source file:com.goftagram.telegram.messenger.NotificationsController.java

public NotificationsController() {
    notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext);
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);
    inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true);

    try {//from w  w w  . j  ava2  s. c o  m
        audioManager = (AudioManager) ApplicationLoader.applicationContext
                .getSystemService(Context.AUDIO_SERVICE);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    try {
        alarmManager = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    try {
        PowerManager pm = (PowerManager) ApplicationLoader.applicationContext
                .getSystemService(Context.POWER_SERVICE);
        notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
        notificationDelayWakelock.setReferenceCounted(false);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    notificationDelayRunnable = new Runnable() {
        @Override
        public void run() {
            FileLog.e("tmessages", "delay reached");
            if (!delayedPushMessages.isEmpty()) {
                showOrUpdateNotification(true);
                delayedPushMessages.clear();
            }
            try {
                if (notificationDelayWakelock.isHeld()) {
                    notificationDelayWakelock.release();
                }
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    };
}

From source file:goo.TeaTimer.TimerActivity.java

/** Called when the activity is first created.
  *   { @inheritDoc} /*  www.j  av  a  2 s .  c om*/
  */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mCancelButton = (ImageButton) findViewById(R.id.cancelButton);
    mCancelButton.setOnClickListener(this);

    mSetButton = (Button) findViewById(R.id.setButton);
    mSetButton.setOnClickListener(this);

    mPauseButton = (ImageButton) findViewById(R.id.pauseButton);
    mPauseButton.setOnClickListener(this);

    mPauseBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pause);

    mPlayBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.play);

    mTimerLabel = (TextView) findViewById(R.id.label);

    mTimerAnimation = (TimerAnimation) findViewById(R.id.imageView);

    enterState(STOPPED);

    // Store some useful values
    mSettings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    mAlarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mSettings.registerOnSharedPreferenceChangeListener(this);

}

From source file:com.jmstudios.redmoon.receiver.AutomaticFilterChangeReceiver.java

public static void cancelPauseAlarm(Context context) {
    Intent commands = new Intent(context, AutomaticFilterChangeReceiver.class);
    commands.setData(Uri.parse("pauseIntent"));
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, commands, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);//  w ww .  j a v  a  2  s  .c  o m
}

From source file:com.b44t.messenger.NotificationsController.java

public NotificationsController() {
    mContext = ApplicationLoader.applicationContext;
    notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext);
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);
    inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true);

    try {/*w w  w.  j  a  v a2 s . c  om*/
        audioManager = (AudioManager) ApplicationLoader.applicationContext
                .getSystemService(Context.AUDIO_SERVICE);
    } catch (Exception e) {
        FileLog.e("messenger", e);
    }
    try {
        alarmManager = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
    } catch (Exception e) {
        FileLog.e("messenger", e);
    }

    try {
        PowerManager pm = (PowerManager) ApplicationLoader.applicationContext
                .getSystemService(Context.POWER_SERVICE);
        notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
        notificationDelayWakelock.setReferenceCounted(false);
    } catch (Exception e) {
        FileLog.e("messenger", e);
    }

    notificationDelayRunnable = new Runnable() {
        @Override
        public void run() {
            FileLog.e("messenger", "delay reached");
            if (!delayedPushMessages.isEmpty()) {
                showOrUpdateNotification(true);
                delayedPushMessages.clear();
            }
            try {
                if (notificationDelayWakelock.isHeld()) {
                    notificationDelayWakelock.release();
                }
            } catch (Exception e) {
                FileLog.e("messenger", e);
            }
        }
    };
}

From source file:com.group13.androidsdk.mycards.NotificationService.java

private void rescheduleNotifications() {

    List<NotificationRule> rules = new ArrayList<>();
    Collections.addAll(rules, MyCardsDBManager.getInstance(this).getAllNotificationRules());
    rules.addAll(getCalendarAsNotificationRules());

    SharedPreferences prefs = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    long lastNotifMillis = prefs.getLong("lastNotifElapsedRealtime", -2 * FIFTEEN_MINUTES);
    SharedPreferences.Editor prefEditor = prefs.edit();

    MyCardsDBManager dbm = MyCardsDBManager.getInstance(this);
    if (!(Math.abs(lastNotifMillis - SystemClock.elapsedRealtime()) < FIFTEEN_MINUTES || dbm.getDoNotDisturb()
            || dateMatchesAnyRule(new Date(), rules)
            || dbm.getCardsForReviewBefore(new Date(), null).length == 0)) {
        lastNotifMillis = SystemClock.elapsedRealtime();
        prefEditor.putLong("lastNotifElapsedRealtime", lastNotifMillis);

        sendNotification();//from  w ww.  j  ava 2s.c o m
    }

    Intent intent = new Intent(this, NotificationService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + FIFTEEN_MINUTES, pi);

    prefEditor.putLong("lastRunElapsedRealtime", SystemClock.elapsedRealtime());
    prefEditor.apply();
}

From source file:com.svpino.longhorn.activities.DashboardActivity.java

@Override
protected void onStart() {
    super.onStart();

    DataProvider.startStockQuoteCollectorService(this, null);

    ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).setInexactRepeating(AlarmManager.RTC,
            System.currentTimeMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES,
            Extensions.createPendingIntent(this, Constants.SCHEDULE_AUTOMATIC));
}

From source file:org.roman.findme.MainActivity.java

void startLocationService() {
    //        Intent intent = new Intent(this, AndroidLocationServices.class);
    //        startService(intent);

    Intent intent = new Intent(this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1253, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarm.cancel(pendingIntent);/*ww  w .ja va  2s .  c  om*/
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_HOUR,
            pendingIntent);

}