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.github.rutvijkumar.twittfuse.Util.java
public static final void scheduleAlarm(Activity activity) { // Construct an intent that will execute the AlarmReceiver Intent intent = new Intent(activity.getApplicationContext(), OfflineTweetAlarmReceiver.class); // Create a PendingIntent to be triggered when the alarm goes off final PendingIntent pIntent = PendingIntent.getBroadcast(activity, OfflineTweetAlarmReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Setup periodic alarm every 10 seconds long firstMillis = System.currentTimeMillis(); // first run of alarm is // immediate//w w w. j av a 2s .c o m int intervalMillis = 10000; // 10 seconds AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE); alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstMillis, intervalMillis, pIntent); }
From source file:com.abid_mujtaba.bitcoin.tracker.services.FetchPriceService.java
public static void stop(Context context) // Method used to stop service via AlarmManager { Intent intent = new Intent(context, FetchPriceService.class); // Intent to launch service PendingIntent alarmIntent = PendingIntent.getService(context, 0, intent, 0); // PendingIntent required by AlarmManager. This gives the AlarmManager permission to launch this Intent as if it were being launched by this application AlarmManager amgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); amgr.cancel(alarmIntent);//from w w w . j av a 2 s . c om Logd("Stopping FetchPriceService."); }
From source file:me.oss.tracker.trackme.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.context = this; textView = (TextView) findViewById(R.id.deviceID); /* Handset mac*/ TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String device_id = tm.getDeviceId(); textView.setText(device_id + ""); Intent alarm = new Intent(this.context, AlarmReceiver.class); boolean alarmRunning = (PendingIntent.getBroadcast(this.context, 0, alarm, PendingIntent.FLAG_NO_CREATE) != null); if (alarmRunning == false) { PendingIntent pendingIntent = PendingIntent.getBroadcast(this.context, 0, alarm, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), LocalLog.syn_time, pendingIntent); }// w w w . j av a2s . c o m mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { mInformationTextView.setText(getString(R.string.gcm_send_message)); } else { mInformationTextView.setText(getString(R.string.token_error_message)); } } }; mInformationTextView = (TextView) findViewById(R.id.informationTextView); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } }
From source file:de.hero.vertretungsplan.CheckForAppUpdate.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { boolean setTimer = intent.getBooleanExtra("setTimer", false); boolean checkNow = intent.getBooleanExtra("checkNow", false); Intent i = new Intent(this, de.hero.vertretungsplan.CheckForAppUpdate.class); i.putExtra("checkNow", true); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.cancel(pi);//from ww w. jav a2s. c om Log.d("CheckForAppUpdate", "Alarm canceled"); if (setTimer) { long lngInterval = AlarmManager.INTERVAL_DAY * 7; Log.d("CheckForAppUpdate", "Alarm set"); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY * 6, lngInterval, pi); //For debugging: after 10 seconds //am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 25000 , AlarmManager.INTERVAL_HOUR , pi); } if (checkNow) { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) { try { new HtmlWorkAppUpdate(this).execute(new URI(getString(R.string.htmlAdresseAktuelleVersion))); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return START_NOT_STICKY; }
From source file:com.metinkale.prayerapp.vakit.AlarmReceiver.java
public static void setAlarm(Context c, Alarm alarm) { AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(c, WakefulReceiver.class); if (alarm != null) { i.putExtra("json", alarm.toString()); int id = alarm.hashCode(); PendingIntent service = PendingIntent.getBroadcast(c, id, i, PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(service);// w ww .j a va 2s.c o m App.setExact(am, AlarmManager.RTC_WAKEUP, alarm.time, service); } }
From source file:org.ounl.lifelonglearninghub.nfcecology.scheduler.SampleAlarmReceiver.java
/** * Sets an alarm/* w w w.ja v a 2s . c om*/ * @param context */ public void setAlarm(Context context) { Log.d(CLASSNAME, "setAlarm"); alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, SampleAlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.MINUTE, iMinsss); Log.d(CLASSNAME, "Setting alarm at " + calendar.getTime()); alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent); ComponentName receiver = new ComponentName(context, SampleBootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:me.futuretechnology.blops.ui.HomeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // startService(new Intent(getApplication(), CleanupService.class)); // if (sharedPrefs.getBoolean(Keys.FIRST_RUN, true)) // {//from w w w.ja v a 2s.c o m // Editor editor = sharedPrefs.edit(); // editor.putBoolean(Keys.FIRST_RUN, false); // editor.apply(); // schedule cleanup service // FIXME temp fix Time time = new Time(); time.setToNow(); // time.hour = 3; // time.minute = 0; // time.second = 0; // ++time.monthDay; // time.normalize(true); Intent intent = new Intent(getApplication(), OnAlarmReceiver.class); intent.setAction(OnAlarmReceiver.ACTION_CLEANUP); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, time.toMillis(true), PendingIntent.getBroadcast(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); // } EventBus.getDefault().register(this); }
From source file:com.google.android.apps.dashclock.PeriodicExtensionRefreshReceiver.java
/** * Cancels the refresh schedule if one isn't set already. */// w w w.ja va 2 s. c o m protected static void cancelPeriodicRefresh(final Context context) { final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = PendingIntent.getBroadcast(context, 0, new Intent(context, PeriodicExtensionRefreshReceiver.class).setAction(ACTION_PERIODIC_ALARM), PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(pi); }
From source file:mobile.tiis.appv2.postman.RoutineAlarmReceiver.java
/** * This part starts the service that checks every 7 days for changes to doses, nonvacinationreasons and tables like these * * @param context//from w w w .j ava 2 s.com */ public static void setAlarmWeeklyUpdateBaseTables(Context context) { if (alarmMgr == null) alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent childChanges = new Intent(context, RoutineAlarmReceiver.class); childChanges.putExtra("weeklyUpdateBaseTables", true); weeklyUpdateBaseTables = PendingIntent.getBroadcast(context, 333, childChanges, PendingIntent.FLAG_UPDATE_CURRENT); alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 604800000, 604800000, weeklyUpdateBaseTables); }
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 w w .java 2s.c om*/ 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())); } }