List of usage examples for android.app AlarmManager INTERVAL_DAY
long INTERVAL_DAY
To view the source code for android.app AlarmManager INTERVAL_DAY.
Click Source Link
From source file:cw.kop.autobackground.LiveWallpaperService.java
private void startAlarms() { if (AppSettings.useTimer() && AppSettings.getTimerDuration() > 0 && PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(LiveWallpaperService.DOWNLOAD_WALLPAPER), PendingIntent.FLAG_NO_CREATE) != null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, AppSettings.getTimerHour()); calendar.set(Calendar.MINUTE, AppSettings.getTimerMinute()); alarmManager.cancel(pendingDownloadIntent); if (calendar.getTimeInMillis() > System.currentTimeMillis()) { alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AppSettings.getTimerDuration(), pendingDownloadIntent); } else {//from w w w . ja v a 2 s .com alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis() + AlarmManager.INTERVAL_DAY, AppSettings.getTimerDuration(), pendingDownloadIntent); } } if (AppSettings.useInterval() && AppSettings.getIntervalDuration() > 0 && PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(LiveWallpaperService.UPDATE_WALLPAPER), PendingIntent.FLAG_NO_CREATE) != null) { alarmManager.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + AppSettings.getIntervalDuration(), AppSettings.getIntervalDuration(), pendingIntervalIntent); } }
From source file:com.mobicage.rogerthat.MainService.java
@Override public int onStartCommand(Intent intent, int flags, int startid) { T.UI();/* ww w. j a va 2 s . c om*/ super.onStartCommand(intent, flags, startid); final Bundle extras = intent == null ? null : intent.getExtras(); boolean launchedAtBootTime = false; boolean launchedByBgDataSettingChange = false; boolean launchedByOnCreate = false; boolean launchedByJustRegistered = false; boolean launchedByGCM = false; try { if (extras != null) { launchedAtBootTime = extras.getBoolean(START_INTENT_BOOTTIME_EXTRAS_KEY, false); launchedByBgDataSettingChange = extras .getBoolean(START_INTENT_BACKGROUND_DATA_SETTING_CHANGED_EXTRAS_KEY, false); launchedByOnCreate = extras.getBoolean(START_INTENT_FROM_ONCREATE_KEY, false); launchedByJustRegistered = extras.getBoolean(START_INTENT_JUST_REGISTERED, false); launchedByGCM = extras.getBoolean(START_INTENT_GCM, false); } if (launchedByGCM) { kickHttpCommunication(true, "Incomming GCM"); return START_STICKY; } final boolean isRegisteredInConfig = getRegisteredFromConfig(); L.d("MainService.onStart \n isIntentNull = " + (intent == null) + "\n isRegisteredInConfig = " + isRegisteredInConfig + "\n launchedAtBootTime = " + launchedAtBootTime + "\n launchedByBgDataSettingChange = " + launchedByBgDataSettingChange + "\n launchedByOnCreate = " + launchedByOnCreate + "\n launchedByJustRegistered = " + launchedByJustRegistered); if (launchedByJustRegistered) { setupNetworkProtocol(); final String myEmail = extras == null ? null : extras.getString(START_INTENT_MY_EMAIL); initializeService(myEmail); } if (!isRegisteredInConfig) { L.d("MainService.onStart() - stopping service immediately"); stopSelf(); return START_NOT_STICKY; } // start networking machinery if (CloudConstants.USE_XMPP_KICK_CHANNEL) mXmppKickChannel.start(); getPlugin(SystemPlugin.class).doHeartbeat(); if (CloudConstants.USE_GCM_KICK_CHANNEL) GoogleServicesUtils.registerGCMRegistrationId(this, null); if (launchedByOnCreate) { kickHttpCommunication(true, "We just got started"); } cleanupOldCachedFiles(false); PendingIntent cleanupDownloadsIntent = PendingIntent.getBroadcast(this, 0, new Intent(INTENT_SHOULD_CLEANUP_CACHED_FILES), 0); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + AlarmManager.INTERVAL_DAY * 7, AlarmManager.INTERVAL_DAY * 7, cleanupDownloadsIntent); return START_STICKY; } finally { if (launchedByGCM) { GCMReveiver.completeWakefulIntent(intent); } } }
From source file:com.codename1.impl.android.AndroidImplementation.java
public void scheduleLocalNotification(LocalNotification notif, long firstTime, int repeat) { final Intent notificationIntent = new Intent(getContext(), LocalNotificationPublisher.class); notificationIntent.setAction(getContext().getApplicationInfo().packageName + "." + notif.getId()); notificationIntent.putExtra(LocalNotificationPublisher.NOTIFICATION, createBundleFromNotification(notif)); Intent contentIntent = new Intent(); if (getActivity() != null) { contentIntent.setComponent(getActivity().getComponentName()); }/*from w ww.j ava2 s.c om*/ contentIntent.putExtra("LocalNotificationID", notif.getId()); if (BACKGROUND_FETCH_NOTIFICATION_ID.equals(notif.getId()) && getBackgroundFetchListener() != null) { Context context = AndroidNativeUtil.getContext(); Intent intent = new Intent(context, BackgroundFetchHandler.class); //there is an bug that causes this to not to workhttps://code.google.com/p/android/issues/detail?id=81812 //intent.putExtra("backgroundClass", getBackgroundLocationListener().getName()); //an ugly workaround to the putExtra bug intent.setData( Uri.parse("http://codenameone.com/a?" + getBackgroundFetchListener().getClass().getName())); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notificationIntent.putExtra(LocalNotificationPublisher.BACKGROUND_FETCH_INTENT, pendingIntent); } else { contentIntent.setData( Uri.parse("http://codenameone.com/a?LocalNotificationID=" + Uri.encode(notif.getId()))); } PendingIntent pendingContentIntent = PendingIntent.getActivity(getContext(), 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); notificationIntent.putExtra(LocalNotificationPublisher.NOTIFICATION_INTENT, pendingContentIntent); PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE); if (BACKGROUND_FETCH_NOTIFICATION_ID.equals(notif.getId())) { alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstTime, getPreferredBackgroundFetchInterval() * 1000, pendingIntent); } else { if (repeat == LocalNotification.REPEAT_NONE) { alarmManager.set(AlarmManager.RTC_WAKEUP, firstTime, pendingIntent); } else if (repeat == LocalNotification.REPEAT_MINUTE) { alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstTime, 60 * 1000, pendingIntent); } else if (repeat == LocalNotification.REPEAT_HOUR) { alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstTime, AlarmManager.INTERVAL_HALF_HOUR, pendingIntent); } else if (repeat == LocalNotification.REPEAT_DAY) { alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstTime, AlarmManager.INTERVAL_DAY, pendingIntent); } else if (repeat == LocalNotification.REPEAT_WEEK) { alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstTime, AlarmManager.INTERVAL_DAY * 7, pendingIntent); } } }