List of usage examples for android.app AlarmManager set
public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation)
Schedule an alarm.
From source file:org.telepatch.android.NotificationsController.java
private void scheduleNotificationRepeat() { try {/*ww w . ja v a2 s . c om*/ AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); if (personal_count > 0) { alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60 * 60 * 1000, pintent); } else { alarm.cancel(pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
public void onClockAlertChanged(long date, boolean set) { /**//from w ww . jav a2s. co m * User could set clock to an unsaved note, so before setting the * alert clock, we should save the note first */ if (!mWorkingNote.existInDatabase()) { saveNote(); } if (mWorkingNote.getNoteId() > 0) { Intent intent = new Intent(this, AlarmReceiver.class); intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId())); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE)); mToolbar.setSubtitle(getSubTitle()); if (!set) { alarmManager.cancel(pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); } } else { /** * There is the condition that user has input nothing (the note is * not worthy saving), we have no note id, remind the user that he * should input something */ Log.e(TAG, "Clock alert setting error"); showToast(R.string.error_note_empty_for_clock); } }
From source file:de.ub0r.android.portaltimer.UpdateReceiver.java
private void schedNext(final Context context) { Log.d(TAG, "schedNext()"); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Log.d(TAG, "current: " + mNow); long t;// w ww.j a va 2s. c o m PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isScreenOn()) { t = mNow + 1000L; } else { t = mNextTarget - mNow; Log.d(TAG, "t: " + t); if (t < 0) { // IllegalState? t = 30000; } else if (t < 30000) { t = 5000; } else if (t < 60000) { t = 15000; } else { t = 30000; } Log.d(TAG, "t: " + t); long diff = mNextTarget - (mNow + t); diff = (diff / 5000) * 5000; Log.d(TAG, "diff: " + diff); if (diff == 0) { t = mNow + 5000; } else { t = mNextTarget - diff - 1000; } } Log.d(TAG, "next: " + t); long et; if (t - System.currentTimeMillis() < 100) { // IllegalState? et = 1000 + SystemClock.elapsedRealtime(); } else { et = t - System.currentTimeMillis() + SystemClock.elapsedRealtime(); } am.set(AlarmManager.ELAPSED_REALTIME, et, PendingIntent.getBroadcast(context, 0, new Intent(context, UpdateReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT)); }
From source file:org.zirco.ui.activities.MainActivity.java
/** * Restart the application.//from ww w . ja v a 2 s . com */ public void restartApplication() { PendingIntent intent = PendingIntent.getActivity(this.getBaseContext(), 0, new Intent(getIntent()), getIntent().getFlags()); AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent); System.exit(2); }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void setSamplingAlarm(String action, long timeOut, int extra) { Log.v(TAG, "LocTrigService: Setting alarm: " + action); cancelSamplingAlarm(action);//from ww w. j a v a2 s. c o m Intent i = new Intent(action); i.setPackage(getPackageName()); i.putExtra(KEY_SAMPLING_ALARM_EXTRA, extra); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); alarmMan.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + timeOut, pi); }
From source file:org.ohmage.triggers.types.location.LocTrigService.java
private void setSamplingAlarm(String action, long timeOut, int extra) { Log.i(DEBUG_TAG, "LocTrigService: Setting alarm: " + action); cancelSamplingAlarm(action);//from ww w . ja va 2 s. c o m Intent i = new Intent(action); i.putExtra(KEY_SAMPLING_ALARM_EXTRA, extra); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); alarmMan.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + timeOut, pi); }
From source file:com.xperia64.timidityae.TimidityActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case PERMISSION_REQUEST: { // If request is cancelled, the result arrays are empty. boolean good = true; if (permissions.length != NUM_PERMISSIONS || grantResults.length != NUM_PERMISSIONS) { good = false;//from w ww. j a v a 2 s . co m } for (int i = 0; i < grantResults.length && good; i++) { if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { good = false; } } if (!good) { // permission denied, boo! Disable the app. //TODO: only disable if files are inaccessible new AlertDialog.Builder(TimidityActivity.this).setTitle("Error") .setMessage("Timidity AE cannot proceed without these permissions") .setPositiveButton("OK", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { TimidityActivity.this.finish(); } }).setCancelable(false).show(); } else { if (!Environment.getExternalStorageDirectory().canRead()) { // Buggy emulator? Try restarting the app AlarmManager alm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); alm.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, PendingIntent.getActivity(this, 237462, new Intent(this, TimidityActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK)); System.exit(0); } yetAnotherInit(); } return; } // other 'case' lines to check for other // permissions this app might request } }
From source file:org.hansel.myAlert.ReminderService.java
@Override public void onCreate() { super.onCreate(); //obtenemos el "nmero de intentos" getApplicationContext().registerReceiver(alarmReceiver, new IntentFilter(CANCEL_ALARM_BROADCAST)); int count = PreferenciasHancel.getReminderCount(getApplicationContext()); count++;/*w ww. j a va2 s .co m*/ PreferenciasHancel.setReminderCount(getApplicationContext(), count); Log.v("Conteo: " + count); if (count >= 3) { //detenemos la alarma del servicio de recordatorios. y lanzamos el servicio de Tracking AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); am.cancel(Util.getReminderPendingIntennt(getApplicationContext())); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); Log.v("Servicio de Rastreo...."); Util.inicarServicio(getApplicationContext()); startService(new Intent(getApplicationContext(), SendPanicService.class)); stopSelf(); } else { //mandamos una alerta de notificacin showNotifciation(); playSound(); mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); Vibra(); Handler han = new Handler(); run = new Runnable() { @Override public void run() { cancelAlarm(); stopSelf(); } }; han.postDelayed(run, 1000 * 10); //alarma para "regresar" en caso que el usuario no de "click" en la notificacin AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); long due = System.currentTimeMillis() + (60000 * 3); // 3 minutos Log.v("Scheduling next update at " + new Date(due)); am.set(AlarmManager.RTC_WAKEUP, due, Util.getReminderPendingIntennt(getApplicationContext())); } }
From source file:com.jins_meme.bridge.MainActivity.java
void restart() { PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, getIntent(), PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 500, pendingIntent); finishAndRemoveTask();/*from www. jav a 2 s .c om*/ }
From source file:me.cpwc.nibblegram.android.NotificationsController.java
private void scheduleNotificationRepeat() { try {/* w w w.j av a2s. co m*/ AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int minutes = preferences.getInt("repeat_messages", 60); if (minutes > 0 && personal_count > 0) { alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + minutes * 60 * 1000, pintent); } else { alarm.cancel(pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }