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:com.example.android.wearable.timer.TimerNotificationService.java
private void deleteTimer() { cancelCountdownNotification();//w ww. j a va 2s . co m AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(Constants.ACTION_SHOW_ALARM, null, this, TimerNotificationService.class); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarm.cancel(pendingIntent); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Timer deleted."); } }
From source file:com.hodor.company.areminder.service.TimerService.java
private void removeAlarm() { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.cancel(1);/*from w w w.j av a 2 s .c o m*/ AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(MainActivity.ACTION_SHOW_ALARM, null, this, TimerService.class); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.cancel(pendingIntent); }
From source file:nl.atcomputing.spacetravelagency.order.DepartureInfoService.java
static public void setupDepartureInfoServiceAlarm(Context context) { Intent intent = new Intent(context, DepartureInfoService.class); PendingIntent pi = PendingIntent.getService(context, 1, intent, 0); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Calendar cal = Calendar.getInstance(); am.setRepeating(AlarmManager.RTC, cal.getTimeInMillis(), 600000, pi); }
From source file:org.pixmob.freemobile.netstat.SyncService.java
public static void schedule(Context context, boolean enabled) { final Context appContext = context.getApplicationContext(); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent syncIntent = PendingIntent.getService(appContext, 0, new Intent(appContext, SyncService.class), PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(syncIntent);//from ww w .j a v a 2 s . c o m if (enabled) { // Set the sync period. long period = AlarmManager.INTERVAL_HOUR; final int syncErrors = context.getSharedPreferences(INTERNAL_SP_NAME, MODE_PRIVATE) .getInt(INTERNAL_SP_KEY_SYNC_ERRORS, 0); if (syncErrors != 0) { // When there was a sync error, the sync period is longer. period = AlarmManager.INTERVAL_HOUR * Math.min(syncErrors, MAX_SYNC_ERRORS); } // Add a random time to prevent concurrent requests for the server. final long fuzz = RANDOM.nextInt(1000 * 60 * 30); period += fuzz; if (DEBUG) { Log.d(TAG, "Scheduling synchronization: next in " + (period / 1000 / 60) + " minutes"); } final long syncTime = System.currentTimeMillis() + period; am.set(AlarmManager.RTC_WAKEUP, syncTime, syncIntent); } else { if (DEBUG) { Log.d(TAG, "Synchronization schedule canceled"); } } }
From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java
public static long createAlarm(Context context, int frequency, int alarmID) { Log.w("UTILS", "createAlarm()"); Intent alarmIntent = new Intent(context, Alarm.class); alarmIntent.putExtra(Alarm.PREF_ALARM_ID, alarmID); PendingIntent pi = PendingIntent.getBroadcast(context, -1, alarmIntent, 0); Random r = new Random(); int addMin = r.nextInt(frequency); if (addMin < 1) { addMin = 1;/*from ww w . j a va 2 s . c o m*/ } Calendar c = Calendar.getInstance(); c.add(Calendar.MINUTE, addMin); c.add(Calendar.SECOND, 0); AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi); return c.getTimeInMillis(); }
From source file:me.mcmadbat.laststats.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement //TODO: find a better way to change users if (id == R.id.Change_User) { user.delete();/*from w ww .j av a 2s. c o m*/ Toast t = Toast.makeText(getApplicationContext(), "Please enter user again", Toast.LENGTH_SHORT); t.show(); Intent mStartActivity = new Intent(getApplicationContext(), MainActivity.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(getApplicationContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); return true; } return super.onOptionsItemSelected(item); }
From source file:am.roadpolice.roadpolice.alarm.AlarmReceiver.java
/** * This function creates a new Alarm by given alarm type. if not {@link AlarmType#NONE} * value was given as a type alarm will be called Daily, Weekly or Monthly staring from * time when this function was called. All alarms which were created before will be canceled. * * @param context Application context//w ww. j ava 2 s . c o m * @param type Alarm Type, accepted values are * {@link AlarmType#NONE} if need to cancel all alarms, * {@link AlarmType#DAILY} alarm will called daily * {@link AlarmType#WEEKLY} alarm will called weekly * {@link AlarmType#MONTHLY} alarm will called monthly */ public static void createAlarm(final Context context, AlarmType type) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); switch (type) { case DAILY: calendar.add(Calendar.DATE, 1); break; case WEEKLY: calendar.add(Calendar.DATE, 7); break; case MONTHLY: calendar.add(Calendar.MONTH, 1); break; } // Create Alarm Manager Object. if (mAlarmManager == null) mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Intent intent = new Intent(context, AlarmReceiver.class); if (mAlarmIntent == null) mAlarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); // Remove all previously created alarms, before creating new one. if (mAlarmManager != null) { mAlarmManager.cancel(mAlarmIntent); // By default Disable Boot Receiver. int componentEnabledState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; // For enabling/disabling Boot Receiver. ComponentName receiver = new ComponentName(context, AlarmReceiver.class); PackageManager pm = context.getPackageManager(); // Set new alarm if provided interval is not none. if (!AlarmType.NONE.equals(type)) { Logger.debug("AlarmReceiver", String .format("----> Next Update Date: %1$tA %1$tb %1$td %1$tY at %1$tI:%1$tM %1$Tp", calendar)); // Enables Boot Receiver. componentEnabledState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; // Set repeating alarm. final long timeInMillis = calendar.getTimeInMillis(); mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeInMillis, type.getValue(), mAlarmIntent); // Stores next Alert Time. PreferenceUtils.storeDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, timeInMillis); } else { PreferenceUtils.storeDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, -1); } pm.setComponentEnabledSetting(receiver, componentEnabledState, PackageManager.DONT_KILL_APP); } }
From source file:com.mech.tech.meet.activities.scenario.MainActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/*from www . ja va2 s . c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(getResources().getColor(R.color.material_wala_deep_blue)); } Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 10); Intent intent = new Intent(this, MyNotificationService.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 36000 * 1000 * 2, pintent); startService(new Intent(getBaseContext(), MyNotificationService.class)); mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); // Set up the drawer. mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); }
From source file:org.opensilk.fuzzyclock.FuzzyWidgetService.java
@Override public void onCreate() { super.onCreate(); mContext = this; //mFormatChangeObserver = new FormatChangeObserver(); //mContext.getContentResolver().registerContentObserver( // Settings.System.CONTENT_URI, true, mFormatChangeObserver //);//w w w . ja va 2s. c om mWidgetManager = AppWidgetManager.getInstance(mContext); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); mFuzzyClock = (FuzzyClockView) layoutInflater.inflate(R.layout.fuzzy_clock, null); }
From source file:com.android.transmart.services.PlaceCheckinService.java
@Override public void onCreate() { super.onCreate(); contentResolver = getContentResolver(); cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); sharedPreferences = getSharedPreferences(LocationConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE); sharedPreferencesEditor = sharedPreferences.edit(); sharedPref = PlatformSpecific.getSharedPreferenceSaver(this); Intent retryIntent = new Intent(LocationConstants.RETRY_QUEUED_CHECKINS_ACTION); retryQueuedCheckinsPendingIntent = PendingIntent.getBroadcast(this, 0, retryIntent, PendingIntent.FLAG_UPDATE_CURRENT); }