Example usage for android.app AlarmManager set

List of usage examples for android.app AlarmManager set

Introduction

In this page you can find the example usage for android.app AlarmManager set.

Prototype

public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation) 

Source Link

Document

Schedule an alarm.

Usage

From source file:org.sipdroid.sipua.ui.Receiver.java

public static void alarm(int renew_time, Class<?> cls) {
    if (!Sipdroid.release)
        Log.i("SipUA:", "alarm " + renew_time);
    Intent intent = new Intent(mContext, cls);
    PendingIntent sender = PendingIntent.getBroadcast(mContext, 0, intent, 0);
    AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    am.cancel(sender);//from w  w w .  ja  v  a2  s .c  om
    if (renew_time > 0)
        am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + renew_time * 1000, sender);
}

From source file:com.brayanarias.alarmproject.receiver.AlarmReceiver.java

private static void setAlarmCumple(Context context) {
    PendingIntent pendingIntent = null;//from  w  w  w  . ja va2  s.  co m
    Intent intent = new Intent(context, AlarmService.class);
    intent.putExtra(Constant.alarmIdKey, 2809);
    intent.putExtra(Constant.alarmNameKey, "Feliz cumple mamita");
    pendingIntent = PendingIntent.getService(context, 2809, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = getAlarmManager(context);
    Calendar actual = Calendar.getInstance();
    actual.set(Calendar.MONTH, 8);
    actual.set(Calendar.DAY_OF_MONTH, 28);
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);
    actual.set(Calendar.HOUR, 5);
    actual.set(Calendar.AM_PM, Calendar.AM);
    actual.set(Calendar.MINUTE, 0);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AlarmManager.AlarmClockInfo clockInfo = new AlarmManager.AlarmClockInfo(actual.getTimeInMillis(),
                pendingIntent);
        alarmManager.setAlarmClock(clockInfo, pendingIntent);
    } else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, actual.getTimeInMillis(), pendingIntent);
    } else {
        alarmManager.set(AlarmManager.RTC_WAKEUP, actual.getTimeInMillis(), pendingIntent);
    }
}

From source file:com.android.mail.utils.NotificationActionUtils.java

/**
 * Registers a timeout for the undo notification such that when it expires, the undo bar will
 * disappear, and the action will be performed.
 *//*from w  ww  . j a  v  a2 s . c  o m*/
public static void registerUndoTimeout(final Context context, final NotificationAction notificationAction) {
    LogUtils.i(LOG_TAG, "registerUndoTimeout for %s", notificationAction.getNotificationActionType());

    if (sUndoTimeoutMillis == -1) {
        sUndoTimeoutMillis = context.getResources().getInteger(R.integer.undo_notification_timeout);
    }

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

    final long triggerAtMills = SystemClock.elapsedRealtime() + sUndoTimeoutMillis;

    final PendingIntent pendingIntent = createUndoTimeoutPendingIntent(context, notificationAction);

    alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtMills, pendingIntent);
}

From source file:MainActivity.java

public void setAlarm(View view) {
    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);
    long thirtyMinutes = SystemClock.elapsedRealtime() + 30 * 1000;
    alarmManager.set(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, alarmIntent);

    //alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, AlarmManager.INTERVAL_HALF_HOUR, alarmIntent);
}

From source file:org.andicar.service.UpdateCheckService.java

private void setNextRun() {
    Calendar cal = Calendar.getInstance();
    if (cal.get(Calendar.HOUR_OF_DAY) >= 18)
        cal.add(Calendar.DAY_OF_YEAR, 1);
    cal.set(Calendar.HOUR_OF_DAY, 20);
    cal.set(Calendar.MINUTE, 0);//from ww w . j  a  v  a2  s  .  c  o m
    Intent i = new Intent(this, UpdateCheckService.class);
    PendingIntent pIntent = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC, cal.getTimeInMillis(), pIntent);
}

From source file:com.rozrost.www.smartlocationreminder.GeofenceTransitionsIntentService.java

private void AlarmService(String PrimaryKey) {
    Intent intent = new Intent("com.rozrost.www.alertscreen.Receiver");
    intent.putExtra("PrimaryKey", PrimaryKey);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 2, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, 0, pendingIntent);
}

From source file:com.sean.takeastand.alarmprocess.UnscheduledRepeatingAlarm.java

private void setAlarm(long triggerTime) {
    PendingIntent pendingIntent = createPendingIntent(mContext);
    AlarmManager am = ((AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE));
    am.set(AlarmManager.ELAPSED_REALTIME, triggerTime, pendingIntent);
}

From source file:com.android.anton.pushnotificationwithgcm.GCMUtil.MyGcmListenerService.java

@Override
public void onTaskRemoved(Intent rootIntent) {
    Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass());
    restartServiceIntent.setPackage(getPackageName());
    PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1,
            restartServiceIntent, PendingIntent.FLAG_ONE_SHOT);

    AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000,
            restartServicePendingIntent);

    super.onTaskRemoved(rootIntent);
}

From source file:com.piggate.samples.PiggateLoginService.Service_Notify.java

@Override
public void onTaskRemoved(Intent rootIntent) {
    Intent restartService = new Intent(getApplicationContext(), this.getClass());
    restartService.setPackage(getPackageName());
    PendingIntent restartServicePI = PendingIntent.getService(getApplicationContext(), 1, restartService,
            PendingIntent.FLAG_ONE_SHOT);
    AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePI);
}

From source file:org.voidsink.anewjkuapp.activity.SettingsActivity.java

@Override
public void onStop() {
    super.onStop();

    PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);

    if (mThemeChanged) {
        Log.i(TAG, "theme changed");

        AlarmManager alm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alm.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
                PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0));

        android.os.Process.killProcess(android.os.Process.myPid());
    }/*from  ww w  .j  a  va2  s .c o  m*/
}