List of usage examples for android.content Context ALARM_SERVICE
String ALARM_SERVICE
To view the source code for android.content Context ALARM_SERVICE.
Click Source Link
From source file:net.texh.cordovapluginstepcounter.StepCounterService.java
@Override public boolean stopService(Intent intent) { Log.i(TAG, "- Received stop: " + intent); //Stop listening to events when stop() is called if (isRunning) { mSensorManager.unregisterListener(this); isRunning = false;//from www. j a v a 2s . c o m } SharedPreferences sharedPref = getSharedPreferences(CordovaStepCounter.USER_DATA_PREF, Context.MODE_PRIVATE); Boolean pActive = CordovaStepCounter.getPedometerIsActive(sharedPref); if (pActive) { Log.i(TAG, "- Relaunch service in 500ms"); //Autorelaunch the service //@TODO should test if stopService is called from killing app or from calling stop() method in CordovaStepCounter Intent newServiceIntent = new Intent(this, StepCounterService.class); AlarmManager aManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); aManager.set(AlarmManager.RTC, java.lang.System.currentTimeMillis() + 500, PendingIntent.getService(this, 11, newServiceIntent, 0)); } else { Log.i(TAG, "StepCounter stopped, will not relaunch service"); } return super.stopService(intent); }
From source file:nu.yona.app.utils.AppUtils.java
@TargetApi(Build.VERSION_CODES.O) public static void cancelPendingWakeUpAlarms(Context context) { Intent alarmIntent = new Intent(context, YonaReceiver.class); alarmIntent.setAction(AppConstant.WAKE_UP); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent);/*www .j a va2 s . c o m*/ }
From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java
@Override public void pause() { //Cancel previous PendingIntent pendingIntent = createPendingIntent(mContext, mCurrentAlarmSchedule); AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); am.cancel(pendingIntent);//from w w w. j av a2 s . c o m endAlarmService(); int totalPauseTime = Utils.getDefaultPauseAmount(mContext); long delayTimeInMillis = totalPauseTime * Constants.secondsInMinute * Constants.millisecondsInSecond; long triggerTime = SystemClock.elapsedRealtime() + delayTimeInMillis; PendingIntent pausePendingIntent = createPausePendingIntent(mContext, mCurrentAlarmSchedule); am.set(AlarmManager.ELAPSED_REALTIME, triggerTime, pausePendingIntent); Calendar pausedUntilTime = Calendar.getInstance(); pausedUntilTime.add(Calendar.MINUTE, Utils.getDefaultPauseAmount(mContext)); Utils.setPausedTime(pausedUntilTime, mContext); Utils.setImageStatus(mContext, Constants.SCHEDULE_PAUSED); }
From source file:com.androidinspain.deskclock.data.TimerModel.java
TimerModel(Context context, SharedPreferences prefs, SettingsModel settingsModel, RingtoneModel ringtoneModel, NotificationModel notificationModel) { mContext = context;// www . ja v a 2 s .co m mPrefs = prefs; mSettingsModel = settingsModel; mRingtoneModel = ringtoneModel; mNotificationModel = notificationModel; mNotificationManager = NotificationManagerCompat.from(context); mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); // Clear caches affected by preferences when preferences change. prefs.registerOnSharedPreferenceChangeListener(mPreferenceListener); // Update timer notification when locale changes. final IntentFilter localeBroadcastFilter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED); mContext.registerReceiver(mLocaleChangedReceiver, localeBroadcastFilter); }
From source file:com.google.android.apps.iosched.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID);//from w ww. j av a 2 s . c o m final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) return; // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData(new Uri.Builder().authority("com.google.android.apps.iosched") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:com.gdgdevfest.android.apps.devfestbcn.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID);/*from www. j a v a2s .c o m*/ final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) return; // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData(new Uri.Builder().authority("com.gdgdevfest.android.apps.devfestbcn") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:org.croudtrip.activities.MainActivity.java
@Override public void init(Bundle savedInstanceState) { // Configure Navigation Drawer this.disableLearningPattern(); this.allowArrowAnimation(); this.setBackPattern(MaterialNavigationDrawer.BACKPATTERN_BACK_TO_FIRST); this.setDrawerHeaderImage(R.drawable.background_drawer); // Get all the saved user data to display some info in the navigation drawer showUserInfoInNavigationDrawer();//from ww w. j a v a 2 s . co m SharedPreferences prefs = getSharedPreferences(Constants.SHARED_PREF_FILE_PREFERENCES, Context.MODE_PRIVATE); // Start timer to update the user's offers all the time if (AccountManager.isUserLoggedIn(this)) { Intent alarmIntent = new Intent(this, LocationUploadTimerReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 120 * 1000, pendingIntent); } // Subscribe to location updates LocationRequest request = LocationRequest.create() //standard GMS LocationRequest .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(10000); ReactiveLocationProvider locationProvider = new ReactiveLocationProvider(this); Subscription locationUpdateSubscription = locationProvider.getUpdatedLocation(request) .subscribe(new Action1<Location>() { @Override public void call(Location location) { locationUpdater.setLastLocation(location); } }); subscriptions.add(locationUpdateSubscription); // GPS availability if (!GPSavailable()) { checkForGPS(); } // Registration for GCM, if we are not registered yet if (!gcmManager.isRegistered()) { Subscription subscription = gcmManager.register().compose(new DefaultTransformer<Void>()).retry(3) .subscribe(new Action1<Void>() { @Override public void call(Void aVoid) { Timber.d("Registered at GCM."); } }, new CrashCallback(this, "failed to register for GCM")); subscriptions.add(subscription); } fillNavigationDrawer(); }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
@Override public void onCreate() { super.onCreate(); Log.i(TAG, "OnCreate"); locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // Stop-detection PI stationaryAlarmPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_ALARM_ACTION), 0); registerReceiver(stationaryAlarmReceiver, new IntentFilter(STATIONARY_ALARM_ACTION)); // Stationary region PI stationaryRegionPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_REGION_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(stationaryRegionReceiver, new IntentFilter(STATIONARY_REGION_ACTION)); // Stationary location monitor PI stationaryLocationPollingPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_LOCATION_MONITOR_ACTION), 0); registerReceiver(stationaryLocationMonitorReceiver, new IntentFilter(STATIONARY_LOCATION_MONITOR_ACTION)); // One-shot PI (TODO currently unused) singleUpdatePI = PendingIntent.getBroadcast(this, 0, new Intent(SINGLE_LOCATION_UPDATE_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(singleUpdateReceiver, new IntentFilter(SINGLE_LOCATION_UPDATE_ACTION)); /////*from w w w .j a va 2 s . co m*/ // DISABLED // Listen to Cell-tower switches (NOTE does not operate while suspended) //telephonyManager.listen(phoneStateListener, LISTEN_CELL_LOCATION); // PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakeLock.acquire(); // Location criteria criteria = new Criteria(); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(true); criteria.setCostAllowed(true); }
From source file:com.example.babycare.fragments.ExampleFragment.java
private void setAlarm(Context context, long second) { Log.i("TAG", "setAlarm()"); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent Intent = new Intent(getActivity(), Temper_Show_Activity.class); PendingIntent pIntent = PendingIntent.getActivity(getActivity(), 0, Intent, 0); alarmManager.set(AlarmManager.RTC, System.currentTimeMillis(), pIntent); Log.i("TAG", "setAlarm()"); }
From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java
private void scheduleAlarm(final long matchId, final long matchStart) { final long currentTime = TimeUtils.getUTCTime(); LOGD(TAG, "Schedule Alarm"); if (currentTime > matchStart) { LOGD(TAG, "CurrentTime > matchStart"); return;/* w w w .j a v a2 s . c o m*/ } long alarmTime = matchStart - MILLI_TEN_MINUTES; final Intent notifIntent = new Intent(ACTION_NOTIFY_MATCH, null, this, ReminderAlarmService.class); notifIntent.setData( new Uri.Builder().authority("ca.zadrox.dota2esportticker").path(String.valueOf(matchId)).build()); notifIntent.putExtra(ReminderAlarmService.EXTRA_MATCH_ID, matchId); notifIntent.putExtra(ReminderAlarmService.EXTRA_MATCH_START, matchStart); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }