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.shafiq.myfeedle.core.MyfeedleService.java

@Override
public void onCreate() {
    super.onCreate();
    // handle version changes
    int currVer = 0;
    try {//from  w ww  .j a  v a2  s  .  c  o  m
        currVer = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    if (!sp.contains(getString(R.string.key_version))
            || (currVer > sp.getInt(getString(R.string.key_version), 0))) {
        sp.edit().putInt(getString(R.string.key_version), currVer).commit();
        try {
            BackupManager.dataChanged(this);
        } catch (Throwable t) {
            Log.d(TAG, "backupagent not supported");
        }
    }
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mConnectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    mMyfeedleCrypto = MyfeedleCrypto.getInstance(getApplicationContext());
    // check the instant upload settings
    startService(Myfeedle.getPackageIntent(getApplicationContext(), MyfeedleUploader.class));
}

From source file:id.ridon.keude.UpdateService.java

public static void schedule(Context ctx) {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "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);//  www  . j  a  v a 2s .  co  m
    if (interval > 0) {
        alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 5000,
                AlarmManager.INTERVAL_HOUR, pending);
        Log.d("Keude", "Update scheduler alarm set");
    } else {
        Log.d("Keude", "Update scheduler alarm not set");
    }

}

From source file:org.ohmage.reminders.notif.Notifier.java

private static void cancelAlarm(Context context, String action) {
    AlarmManager alarmMan = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    Intent i = new Intent(context, NotifReceiver.class).setAction(action);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_NO_CREATE);

    if (pi != null) {
        alarmMan.cancel(pi);/* www. j a v a 2s. c  om*/
        pi.cancel();
    }
}

From source file:com.robsterthelobster.ucibustracker.ArrivalsFragment.java

private void updateRouteData() {
    Intent alarmIntent = new Intent(getActivity(), UciBusIntentService.AlarmReceiver.class);

    PendingIntent pi = PendingIntent.getBroadcast(getActivity(), 0, alarmIntent, 0);

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

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 0);
    long frequency = 60 * 1000; // one minute, which is the minimum

    am.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), frequency, pi);
}

From source file:com.home.pr.opendoor.MainActivity.java

public void schedulePeriodicUpdate() {
    /*final Handler handler = new Handler();
    handler.postDelayed(new Runnable(){//from   w  w w .j av  a  2s . co  m
    @Override
    public void run() {
        handler.postDelayed(this,10000);
        Intent intent = new Intent(getApplicationContext(), AdafruitDoorStatus.class);
        getApplicationContext().startService(intent);
    }
    },10000);*/
    Intent intent = new Intent(this, StatusReceiver.class);
    PendingIntent pIntent = PendingIntent.getBroadcast(this, StatusReceiver.REQUEST_CODE, intent, 0);
    long firstMillis = System.currentTimeMillis();
    AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstMillis, 10000, pIntent);
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

public static void deleteAlarm(Context context, Lecture lecture) {
    AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(context);
    SQLiteDatabase db = alarmDB.getWritableDatabase();
    Cursor cursor;//from w w  w.  j av  a2s  . c om

    try {
        cursor = db.query(AlarmsTable.NAME, AlarmsDBOpenHelper.allcolumns, AlarmsTable.Columns.EVENT_ID + "=?",
                new String[] { lecture.lecture_id }, null, null, null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        MyApp.LogDebug("delete alarm", "failure on alarm query");
        db.close();
        return;
    }

    if (cursor.getCount() == 0) {
        db.close();
        cursor.close();
        MyApp.LogDebug("delete_alarm", "alarm for " + lecture.lecture_id + " not found");
        return;
    }

    cursor.moveToFirst();

    Intent intent = new Intent(context, AlarmReceiver.class);

    String lecture_id = cursor.getString(cursor.getColumnIndex(AlarmsTable.Columns.EVENT_ID));
    intent.putExtra(BundleKeys.ALARM_LECTURE_ID, lecture_id);
    int day = cursor.getInt(cursor.getColumnIndex(AlarmsTable.Columns.DAY));
    intent.putExtra(BundleKeys.ALARM_DAY, day);
    String title = cursor.getString(cursor.getColumnIndex(AlarmsTable.Columns.EVENT_TITLE));
    intent.putExtra(BundleKeys.ALARM_TITLE, title);
    long startTime = cursor.getLong(cursor.getColumnIndex(AlarmsTable.Columns.TIME));
    intent.putExtra(BundleKeys.ALARM_START_TIME, startTime);

    // delete any previous alarms of this lecture
    db.delete(AlarmsTable.NAME, AlarmsTable.Columns.EVENT_ID + "=?", new String[] { lecture.lecture_id });
    db.close();

    intent.setAction("de.machtnix.fahrplan.ALARM");
    intent.setData(Uri.parse("alarm://" + lecture.lecture_id));

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingintent = PendingIntent.getBroadcast(context, Integer.parseInt(lecture.lecture_id),
            intent, 0);

    // Cancel any existing alarms for this lecture
    alarmManager.cancel(pendingintent);

    lecture.has_alarm = false;
}

From source file:org.xwalk.app.template.AppTemplateActivity.java

public static void set_RTC_wakeup(Context context) {

    Log.d(TAG, "setting RTC wakeup");

    alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, UCCLauncherReceiver.class);
    intent.setAction(WAKEUP_SIG);/*from ww  w  .jav  a 2 s. c  o  m*/
    alarmIntent_Wakeup = PendingIntent.getBroadcast(context, 0, intent, 0);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, wakeup_rtc_time_hours);
    calendar.set(Calendar.MINUTE, wakeup_rtc_time_minutes);

    // cancel old intent (if any)
    alarmMgr.cancel(alarmIntent_Wakeup);

    // set new intent

    // alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
    // SystemClock.elapsedRealtime() + 2 * 60 * 1000, alarmIntent_Wakeup);

    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            alarmIntent_Wakeup);
}

From source file:com.QuarkLabs.BTCeClient.MainActivity.java

/**
 * Sets up alarm used for periodic check
 *
 * @param msecs Checking period//from ww  w .j a  va2 s .c o m
 */
public void setRecurringAlarm(long msecs) {
    Intent downloader = new Intent(this, StartServiceReceiver.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pendingIntent = PendingIntent.getBroadcast(this, 0, downloader, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, msecs,
            pendingIntent);
    alarmSet = true;
}

From source file:at.diamonddogs.util.CacheManager.java

/**
 * Turn off scheduled cache cleaning/*w w w. j a v a2s.  c  o  m*/
 *
 * @param context a {@link Context}
 */
public void disableScheduledCacheCleaner(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.cancel(getAlarmIntent(context));
    Log.i(TAG, "Cache cleaning alarm has been disabled.");
}

From source file:com.android.deskclock.alarms.AlarmStateManager.java

/**
 * Used in L and later devices where "next alarm" is stored in the Alarm Manager.
 *///from w  w  w.j  a va 2s .  c o m
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void updateNextAlarmInAlarmManager(Context context, AlarmInstance nextAlarm) {
    // Sets a surrogate alarm with alarm manager that provides the AlarmClockInfo for the
    // alarm that is going to fire next. The operation is constructed such that it is ignored
    // by AlarmStateManager.

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

    int flags = nextAlarm == null ? PendingIntent.FLAG_NO_CREATE : 0;
    PendingIntent operation = PendingIntent.getBroadcast(context, 0 /* requestCode */,
            AlarmStateManager.createIndicatorIntent(context), flags);

    if (nextAlarm != null) {
        long alarmTime = nextAlarm.getAlarmTime().getTimeInMillis();

        // Create an intent that can be used to show or edit details of the next alarm.
        PendingIntent viewIntent = PendingIntent.getActivity(context, nextAlarm.hashCode(),
                AlarmNotifications.createViewAlarmIntent(context, nextAlarm),
                PendingIntent.FLAG_UPDATE_CURRENT);

        AlarmManager.AlarmClockInfo info = new AlarmManager.AlarmClockInfo(alarmTime, viewIntent);
        alarmManager.setAlarmClock(info, operation);
    } else if (operation != null) {
        alarmManager.cancel(operation);
    }
}