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:damo.three.ie.prepay.ConnectivityReceiver.java
@Override public void onReceive(Context context, Intent intent) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (sharedPrefs.getBoolean("backgroundupdate", true) && !(sharedPrefs.getString("mobile", "").equals("") && sharedPrefs.getString("password", "").equals(""))) { Log.d(Constants.TAG, "Internet back!! updating usage!"); Intent receiver = new Intent(context, UpdateReceiver.class); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Using different request code to 0 so it won't conflict main repeating alarm. PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 2, receiver, PendingIntent.FLAG_UPDATE_CURRENT); // Keeping efficiency in mind: // http://developer.android.com/reference/android/app/AlarmManager.html#ELAPSED_REALTIME am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), pendingIntent); // Disable receiver after we scheduled an update. disableReceiver(context);//w w w . j av a 2 s. co m } }
From source file:com.ekasoft.promoexito.MyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(com.ekasoft.promoexito.R.layout.activity_my); Settings.set(this, "promo_order", "false"); if (!Settings.isKey(this, "install")) { Calendar cal = Calendar.getInstance(); Intent intent = new Intent(this, ServiceWithWebView.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 24 * 60 * 60 * 1000, pintent); Intent intent2 = new Intent(MyActivity.this, InstallPromoActivity.class); startActivity(intent2);//from ww w.j a v a2 s . co m finish(); } ActionBar ab = getSupportActionBar(); ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffe800"))); ab.setIcon(com.ekasoft.promoexito.R.drawable.bar); ab.setLogo(com.ekasoft.promoexito.R.drawable.bar); ab.setDisplayUseLogoEnabled(true); ab.setHomeAsUpIndicator(com.ekasoft.promoexito.R.drawable.bar); ab.setDisplayHomeAsUpEnabled(true); ab.setTitle(""); ActiveAndroid.initialize(this); mAdView = (AdView) findViewById(com.ekasoft.promoexito.R.id.ad_view); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) //.addTestDevice("4CBD3F38AF88E4EFA5FC4FB8B02D8D73") .build(); mAdView.loadAd(adRequest); listPromo = new FragmentListPromo(); listCategories = new CategorysFragment(); getSupportFragmentManager().beginTransaction() .add(com.ekasoft.promoexito.R.id.fragment_container, listPromo).commit(); }
From source file:cn.studyjams.s2.sj0119.NForget.AlarmReceiver.java
public void setAlarm(Context context, Calendar calendar, int ID) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification time Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using notification time mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncManager.java
/** * Set up the alarm./* w w w .j av a 2 s . c o m*/ * * @param trigger * when the alarm should first trigger in milliseconds. */ public void setSyncAlarm(long trigger) { Log.d(TAG, "Setting up sync alarm"); final Context context = getContext(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final boolean doBackgroundUpdates = prefs.getBoolean(SettingsActivity.KEY_BACKGROUND_UPDATES, true); if (doBackgroundUpdates) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = getAlarmPendingIntent(); if (pi == null) { pi = createAlarmPendingIntent(); } am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + trigger, INTERVAL, pi); } }
From source file:org.pixmob.freemobile.netstat.SyncServiceTesting.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, SyncServiceTesting.class), PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(syncIntent);/*from www.j a va 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:ch.fixme.status.Widget.java
protected static void setAlarm(Context ctxt, Intent i, int widgetId, int delay) { // Get interval SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt); long update_interval = Long .parseLong(prefs.getString(Prefs.KEY_CHECK_INTERVAL, Prefs.DEFAULT_CHECK_INTERVAL)) * 60L * 1000L; // Set alarm/*from w w w. j a va2 s. c om*/ AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = PendingIntent.getService(ctxt, widgetId, i, 0); am.cancel(pi); am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + delay, update_interval, pi); // Log.i(Main.TAG, "start notification every " + update_interval / 1000 // + "s"); }
From source file:alaindc.memenguage.RandomIntentService.java
private void setTimeout() { // Set the alarms for next sensing of amplitude alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(getApplicationContext(), RandomIntentService.class); intentAlarm.setAction(Constants.ACTION_RANDOM_WORD); alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0); try {//from w w w . j av a 2s . c om // Remove the oldest one if exists alarmMgr.cancel(alarmIntent); } catch (Exception e) { Log.d("Randomintentservice", "Cancel pending intent error"); } long millisec = Long.parseLong( PreferenceManager.getDefaultSharedPreferences(this).getString("interval_notifications", "120")) * 60 * 1000; alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + millisec, alarmIntent); }
From source file:edu.rit.csh.androidwebnews.RecentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); newsgroupListMenu = new NewsgroupListMenu(this); newsgroupListMenu.checkEnabled();//from w w w . jav a2 s . c o m dialog = new InvalidApiKeyDialog(this); connectionDialog = new ConnectionExceptionDialog(this); ftd = new FirstTimeDialog(this); setContentView(R.layout.activity_recent); rf = (RecentFragment) getSupportFragmentManager().findFragmentById(R.id.recent_fragment); if (!sharedPref.getBoolean("first_time", true)) { hc.getNewest(true); if (!sharedPref.getString("newsgroups_json_string", "").equals("")) { newsgroupListMenu .update(hc.getNewsGroupFromString(sharedPref.getString("newsgroups_json_string", ""))); hc.startUnreadCountTask(); } else { hc.getNewsGroups(); } Intent intent = new Intent(this, UpdaterService.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // if the run service is selected, an alarm is started to repeat over given time if (sharedPref.getBoolean("run_service", false)) { String timeString = sharedPref.getString("time_between_checks", "15"); int time = 15; if (!timeString.equals("")) { time = Integer.valueOf(timeString); } alarm.cancel(pintent); alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), time * 60000, pintent); } else { alarm.cancel(pintent); } } else { ftd.show(); SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("first_time", false); editor.commit(); } setTitle("Recent Posts"); }
From source file:com.cyanogenmod.account.util.CMAccountUtils.java
public static void scheduleRetry(Context context, SharedPreferences prefs, Intent intent) { int backoffTimeMs = getBackoff(prefs); int nextAttempt = backoffTimeMs / 2 + sRandom.nextInt(backoffTimeMs); if (CMAccount.DEBUG) Log.d(TAG, "Scheduling retry, backoff = " + nextAttempt + " (" + backoffTimeMs + ") for " + intent.getAction());/*from ww w . j a v a 2 s . c o m*/ PendingIntent retryPendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + nextAttempt, retryPendingIntent); if (backoffTimeMs < CMAccount.MAX_BACKOFF_MS) { setBackoff(prefs, backoffTimeMs * 2); } }
From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java
public void setAlarm(Context context, Calendar calendar, int ID) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AutomuteAlarmReceiver.class); intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification time Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using notification time mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }