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:mobile.tiis.appv2.postman.RoutineAlarmReceiver.java

/**
 * Sets a repeating alarm that runs once every 5 minutes When the
 * alarm fires, the appv2 broadcasts an Intent to this WakefulBroadcastReceiver.
 *
 * @param context/*from w  w  w . ja v a2 s .com*/
 */
public static void setPostmanAlarm(Context context) {
    if (alarmMgr == null)
        alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, RoutineAlarmReceiver.class);
    intent.putExtra("setPostmanAlarm", true);
    alarmIntent = PendingIntent.getBroadcast(context, 111, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 30000,
            30000, alarmIntent);
}

From source file:org.hansel.myAlert.StopScheduleActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    am.cancel(Util.getReminderPendingIntennt(getApplicationContext()));
    PreferenciasHancel.setAlarmStartDate(getApplicationContext(), 0);
    //ya se termino el tiempo de la programacin cancelamos alarma y salimos
    Log.v("Fin de la programacin");
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Rastreo Finalizado")
            .setContentText("Gracias por usar Hancel");

    Notification notif = mBuilder.build();
    notif.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0, notif);
    finish();/*from  w w  w .  java  2 s  . co  m*/
    return;
}

From source file:dk.kk.cykelsuperstier.reminders.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    if (getAbortBroadcast()) {
        return;/*from   w ww. jav a 2 s  .c o m*/
    }
    int repetition = intent.getExtras().getInt("repetition");
    if (repetition >= 0) {
        // Find next alarm time.
        // If repetition is EVERY_DAY no need to set again, reminder was
        // initially set repetitive.+
        Calendar nextAlarmTime = AlarmUtils.calculateNextAlarmTime(repetition);
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent newIntent = new Intent(AlarmUtils.ALARM_ACTION);
        newIntent.putExtra("repetition", repetition);
        PendingIntent sender = PendingIntent.getBroadcast(context,
                CykelPlanenApplication.ALARM_REQUEST_CODE + 1, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        am.set(AlarmManager.RTC_WAKEUP, nextAlarmTime.getTimeInMillis(), sender);
    }

    createNotification(context, repetition);
}

From source file:com.ivarprudnikov.sensors.OnBootBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Starts service responsible for sensor data storage
    Intent startSensorDataServiceIntent = new Intent(context, OnAlarmBroadcastReceiver.class);
    startSensorDataServiceIntent.setAction(Constants.INTENT_ACTION_TRIGGER_FROM_BOOT);
    PendingIntent pi1 = PendingIntent.getBroadcast(context, 0, startSensorDataServiceIntent, 0);
    mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + START_AT_OFFSET, pi1);

    // Registers alarms required for data export
    Intent startDataExportIntent = new Intent(context, OnExportAlarmBroadcastReceiver.class);
    startDataExportIntent.setAction(Constants.INTENT_ACTION_TRIGGER_FROM_BOOT);
    PendingIntent pi2 = PendingIntent.getBroadcast(context, 0, startSensorDataServiceIntent, 0);
    mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + START_AT_OFFSET, pi2);
}

From source file:me.acristoffers.tracker.AlarmReceiver.java

public static void setAlarm(final Context context) {
    try {/*from   www  .  ja  va2s . c  om*/
        final Intent intent = new Intent(context, AlarmReceiver.class);
        final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

        final long fiveMinutes = 5 * 60 * 1000;

        final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
        final String minutes = sharedPref.getString("sync_interval", "15");

        long repeatMinutes;
        try {
            repeatMinutes = Long.parseLong(minutes) * 60 * 1000;
        } catch (NumberFormatException e) {
            repeatMinutes = 15 * 60 * 1000;
        }

        final boolean active = sharedPref.getBoolean("autosync", true);

        if (active) {
            alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, fiveMinutes, repeatMinutes,
                    pendingIntent);
        } else {
            alarmManager.cancel(pendingIntent);
        }
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:com.spoiledmilk.cykelsuperstier.reminders.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    if (getAbortBroadcast()) {
        return;// ww w  .  ja va2s.  c o m
    }
    int repetition = intent.getExtras().getInt("repetition");
    if (repetition >= 0) {
        // Find next alarm time.
        // If repetition is EVERY_DAY no need to set again, reminder was
        // initially set repetitive.+
        Calendar nextAlarmTime = AlarmUtils.calculateNextAlarmTime(repetition);
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent newIntent = new Intent(AlarmUtils.ALARM_ACTION);
        newIntent.putExtra("repetition", repetition);
        PendingIntent sender = PendingIntent.getBroadcast(context,
                CykelsuperstierApplication.ALARM_REQUEST_CODE + 1, newIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        am.set(AlarmManager.RTC_WAKEUP, nextAlarmTime.getTimeInMillis(), sender);
    }

    createNotification(context, repetition);
}

From source file:com.commonsware.android.job.PollReceiver.java

@Override
public void onReceive(Context ctxt, Intent i) {
    boolean isDownload = i.getBooleanExtra(EXTRA_IS_DOWNLOAD, false);
    startWakefulService(ctxt,/*from ww w.ja  v  a2s.  com*/
            new Intent(ctxt, DemoScheduledService.class).putExtra(EXTRA_IS_DOWNLOAD, isDownload));

    long period = i.getLongExtra(EXTRA_PERIOD, -1);

    if (period > 0) {
        scheduleExactAlarm(ctxt, (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE), period,
                isDownload);
    }
}

From source file:net.callmeike.android.alarmscheduler.scheduler.AlarmScheduler.java

public static void stopSampleTask(Context ctxt) {
    ((AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE)).cancel(getTaskIntent(ctxt, SAMPLE_TASK));
    Log.d(TAG, "sample task stopped");
}

From source file:MainActivity.java

public void cancelAlarm() {
    Intent intentToFire = new Intent(getApplicationContext(), AlarmBroadcastReceiver.class);
    intentToFire.setAction(AlarmBroadcastReceiver.ACTION_ALARM);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intentToFire, 0);
    AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(alarmIntent);/*from  w  ww.  ja va  2s .co m*/
}

From source file:net.eledge.android.europeana.service.receiver.BlogCheckerReceiver.java

public void enableBlogChecker(Context context) {
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, BlogCheckerReceiver.class);
    blogCheckerIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, INTERVAL, INTERVAL,
            blogCheckerIntent);//from ww  w  . j av a  2 s.c o  m

    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();

    if (pm != null) {
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }
}