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

/**
 * This part starts the service that checks every 10 minutes for changes to child data
 *
 * @param context/*from   w  w w. j av a2  s  .c  o m*/
 */
public static void setAlarmCheckForChangesInChild(Context context) {
    if (alarmMgr == null)
        alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent childChanges = new Intent(context, RoutineAlarmReceiver.class);
    childChanges.putExtra("childChanges", true);
    checkForChangesInChildPI = PendingIntent.getBroadcast(context, 222, childChanges,
            PendingIntent.FLAG_UPDATE_CURRENT); //
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            Calendar.getInstance().getTimeInMillis() + (5 * 60000), (5 * 60000), checkForChangesInChildPI);
}

From source file:com.devnoobs.bmr.Powiadomienia.java

public void setAlarm(int h, int m) {
    Calendar calendar = przygotujCzas(h, m);

    AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);

    Intent i = new Intent(S);
    PendingIntent pi = PendingIntent.getBroadcast(c, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    IntentFilter intentFilter = new IntentFilter(S);
    Powiadomienia p = new Powiadomienia();
    c.registerReceiver(p, intentFilter);

    am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60 * 10, pi); // Millisec * Sec * Min
    //am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), AlarmManager.INTERVAL_DAY, pi); //   
    showToast("Powiadomienie wlaczone");
}

From source file:at.florian_lentsch.expirysync.NotifyChecker.java

/**
 * Sets the alarm that checks for products soon to expire (or already have
 * expired)/*from w  w  w  .  j  a va 2  s . c  o  m*/
 * 
 * @param context
 */
protected static void setAlarm(Context context) {
    Context appContext = context.getApplicationContext();
    Intent receiverIntent = new Intent(appContext, NotifyChecker.class);

    // Fetch info about when the alarm is to sound each day from the shared
    // preferences:
    long firstStartMillis = getFirstStartMillis(appContext);
    if (firstStartMillis < 0) {
        Log.i("Alarm", "Alert time not configured - not setting alarm");
        return;
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(firstStartMillis);
    // Log.i("Alarm", "Setting alarm: " + firstStartMillis + ", " + (new
    // SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",
    // Locale.US)).format(firstStartMillis));

    // Set the alarm:
    PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, 0, receiverIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, firstStartMillis, AlarmManager.INTERVAL_DAY, alarmIntent);
}

From source file:nkarasch.repeatingreminder.scheduling.AlertBroadcastReceiver.java

/**
 * Schedules the next firing of this BroadcastReceiver based on the data in the Alert and fires the
 * Alert if appropriate//from   www  .java2 s  .c  o  m
 */
@Override
public void onReceive(Context context, Intent intent) {

    Alert alert = intent.getParcelableExtra("alert");
    boolean initial = intent.getBooleanExtra("initial", false);

    intent.putExtra("initial", false);
    Calendar nextTime = getNextTime(Calendar.getInstance(), alert);
    if (nextTime != null) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        PendingIntent sender = PendingIntent.getBroadcast(context, alert.getId(), intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        alarmManager.set(AlarmManager.RTC_WAKEUP, nextTime.getTimeInMillis(), sender);
    }

    if (initial) {
        return;
    }

    Calendar calendar = Calendar.getInstance();
    if (!alert.isSchedule()) {
        fireNotification(context, alert);
    } else {
        if (isLegalDay(calendar, alert) && isLegalTime(calendar, alert) == DAY_POSITION.BETWEEN) {
            fireNotification(context, alert);
        }
    }
}

From source file:com.abid_mujtaba.bitcoin.tracker.services.FetchPriceService.java

public static void start(Context context) // Method used to start service via AlarmManager
{
    Intent intent = new Intent(context, FetchPriceService.class); // Intent to launch service
    PendingIntent alarmIntent = PendingIntent.getService(context, 0, intent, 0); // PendingIntent required by AlarmManager. This gives the AlarmManager permission to launch this Intent as if it were being launched by this application

    AlarmManager amgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    amgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), INTERVAL, alarmIntent);
}

From source file:com.yeldi.yeldibazaar.UpdateService.java

public static void schedule(Context ctx) {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String sint = prefs.getString("updateInterval", "0");
    int interval = Integer.parseInt(sint);

    Intent intent = new Intent(ctx, UpdateService.class);
    PendingIntent pending = PendingIntent.getService(ctx, 0, intent, 0);

    AlarmManager alarm = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    alarm.cancel(pending);/* w  w  w . ja  v  a 2s . c  o  m*/
    if (interval > 0) {
        alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 5000,
                AlarmManager.INTERVAL_HOUR, pending);
        Log.d("FDroid", "Update scheduler alarm set");
    } else {
        Log.d("FDroid", "Update scheduler alarm not set");
    }

}

From source file:com.bhb27.isu.services.BootBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // only run if the app has run before and main has extracted asserts
    String action = intent.getAction();
    boolean run_boot = Tools.getBoolean("run_boot", false, context);
    boolean rootAccess = Tools.rootAccess(context);
    if (Intent.ACTION_BOOT_COMPLETED.equals(action) && rootAccess && run_boot) {
        Log.d(TAG, " Started action " + action + " run_boot " + run_boot);

        if (Tools.getBoolean("prop_run", false, context) && Tools.getBoolean("apply_props", false, context))
            ContextCompat.startForegroundService(context, new Intent(context, PropsService.class));

        ContextCompat.startForegroundService(context, new Intent(context, BootService.class));

        if (Tools.getBoolean("apply_su", false, context) && Tools.SuVersionBool(Tools.SuVersion(context))) {

            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            Intent serviceIntent = new Intent("com.bhb27.isu.services.SuServiceReceiver.RUN");
            serviceIntent.putExtra("RUN", 100);
            serviceIntent.setClass(context, SuServiceReceiver.class);
            serviceIntent.setAction("RUN");

            PendingIntent pi = PendingIntent.getBroadcast(context, 100, serviceIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                    + Integer.valueOf(Tools.readString("apply_su_delay", "0", context)), pi);
        }/*from w  w  w. ja v a  2s  .c  om*/

    } else
        Log.d(TAG, "Not Started action " + action + " rootAccess " + rootAccess + " run_boot " + run_boot);
}

From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java

public static void cancelAlarm(Context context, Schedule schedule) {
    Intent intent = new Intent(context, Alarm.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, SystemUtils.safeLongToInt(schedule.getId()), intent,
            0);/*from  w  w  w  .  j  a  v  a  2  s  . co  m*/
    AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmMgr.cancel(pi);
}

From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java

@Override
public void onDisabled(Context context) {
    super.onDisabled(context);

    // remove the update alarm if the last widget is gone
    Intent update = new Intent(UPDATE);
    PendingIntent pi = PendingIntent.getBroadcast(context, 195, update, 0);

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pi);/*w ww . ja v a 2 s .  co  m*/
}

From source file:com.bluros.music.widgets.SleepModeDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    context = getActivity().getBaseContext();
    Intent action = new Intent(MusicService.SLEEP_MODE_STOP_ACTION);
    ComponentName serviceName = new ComponentName(context, MusicService.class);
    action.setComponent(serviceName);// ww  w.  ja va  2  s  .c o  m
    pendingIntent = PendingIntent.getService(context, 4, action, 0);
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.sleep_mode_time_selector, null);
    int minutes = Integer.valueOf(getString(R.string.default_interval));
    final TextView tvPopUpTime = (TextView) view.findViewById(R.id.pop_up_time);
    tvPopUpTime.setText(String.valueOf(minutes));
    final SeekBar sBar = (SeekBar) view.findViewById(R.id.seekbar);
    sBar.setProgress(minutes - 1);
    sBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            tvPopUpTime.setText(String.valueOf(arg1 + 1));
        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }
    });
    builder.setTitle(R.string.select_quit_time);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int arg1) {
            long timeLeft = (sBar.getProgress() + 1) * mMill;
            alarmManager.set(AlarmManager.RTC_WAKEUP, timeLeft + System.currentTimeMillis(), pendingIntent);
            MusicPlayer.setSleepMode(true);
            Toast.makeText(context, String.format(getString(R.string.quit_warining), sBar.getProgress() + 1),
                    Toast.LENGTH_SHORT).show();
            dialog.dismiss();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int arg1) {
            dialog.dismiss();
        }
    });
    builder.setView(view);
    return builder.create();
}