List of usage examples for android.text.format DateUtils MINUTE_IN_MILLIS
long MINUTE_IN_MILLIS
To view the source code for android.text.format DateUtils MINUTE_IN_MILLIS.
Click Source Link
From source file:com.csipsimple.ui.messages.MessageAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final MessageListItemViews tagView = (MessageListItemViews) view.getTag(); SipMessage msg = new SipMessage(cursor); String number = msg.getRemoteNumber(); long date = msg.getDate(); String subject = msg.getBodyContent(); String errorTxt = msg.getErrorContent(); String mimeType = msg.getMimeType(); int type = msg.getType(); String timestamp = ""; if (System.currentTimeMillis() - date > 1000 * 60 * 60 * 24) { // If it was recieved one day ago or more display relative // timestamp - SMS like behavior int flags = DateUtils.FORMAT_ABBREV_RELATIVE; timestamp = (String) DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags); } else {// w w w. jav a 2 s.c o m // If it has been recieved recently show time of reception - IM // like behavior timestamp = dateFormatter.format(new Date(date)); } tagView.dateView.setText(timestamp); // Delivery state if (type == SipMessage.MESSAGE_TYPE_QUEUED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_email_pending); tagView.deliveredIndicator.setContentDescription(mContext.getString(R.string.status_pending)); } else if (type == SipMessage.MESSAGE_TYPE_FAILED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_sms_mms_not_delivered); tagView.deliveredIndicator .setContentDescription(mContext.getString(R.string.undelivered_msg_dialog_title)); } else { tagView.deliveredIndicator.setVisibility(View.GONE); tagView.deliveredIndicator.setContentDescription(""); } if (TextUtils.isEmpty(errorTxt)) { tagView.errorView.setVisibility(View.GONE); } else { tagView.errorView.setVisibility(View.VISIBLE); tagView.errorView.setText(errorTxt); } // Subject tagView.contentView.setText(formatMessage(number, subject, mimeType)); if (msg.isOutgoing()) { setPhotoSide(tagView, ArrowPosition.LEFT); // Photo tagView.quickContactView.assignContactUri(personalInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); } else { setPhotoSide(tagView, ArrowPosition.RIGHT); // Contact CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, msg.getFullFrom()); // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); } }
From source file:com.abcvoipsip.ui.messages.MessageAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final MessageListItemViews tagView = (MessageListItemViews) view.getTag(); SipMessage msg = new SipMessage(cursor); String number = msg.getRemoteNumber(); long date = msg.getDate(); String subject = msg.getBodyContent(); String errorTxt = msg.getErrorContent(); String mimeType = msg.getMimeType(); int type = msg.getType(); String timestamp = ""; if (System.currentTimeMillis() - date > 1000 * 60 * 60 * 24) { // If it was recieved one day ago or more display relative // timestamp - SMS like behavior int flags = DateUtils.FORMAT_ABBREV_RELATIVE; timestamp = (String) DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags); } else {//from w ww. jav a 2 s . co m // If it has been recieved recently show time of reception - IM // like behavior timestamp = dateFormatter.format(new Date(date)); } tagView.dateView.setText(timestamp); // Delivery state if (type == SipMessage.MESSAGE_TYPE_QUEUED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_email_pending); tagView.deliveredIndicator.setContentDescription(mContext.getString(R.string.status_pending)); } else if (type == SipMessage.MESSAGE_TYPE_FAILED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_sms_mms_not_delivered); tagView.deliveredIndicator .setContentDescription(mContext.getString(R.string.undelivered_msg_dialog_title)); } else { tagView.deliveredIndicator.setVisibility(View.GONE); tagView.deliveredIndicator.setContentDescription(""); } if (TextUtils.isEmpty(errorTxt)) { tagView.errorView.setVisibility(View.GONE); } else { tagView.errorView.setVisibility(View.VISIBLE); tagView.errorView.setText(errorTxt); } // Subject tagView.contentView.setText(formatMessage(number, subject, mimeType)); if (msg.isOutgoing()) { setPhotoSide(tagView, ArrowPosition.LEFT); // Photo tagView.quickContactView.assignContactUri(personalInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, SipHome.USE_LIGHT_THEME ? R.drawable.ic_contact_picture_holo_light : R.drawable.ic_contact_picture_holo_dark); } else { setPhotoSide(tagView, ArrowPosition.RIGHT); // Contact CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, msg.getFullFrom()); // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, SipHome.USE_LIGHT_THEME ? R.drawable.ic_contact_picture_holo_light : R.drawable.ic_contact_picture_holo_dark); } }
From source file:com.newcell.calltext.ui.messages.MessageAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final MessageListItemViews tagView = (MessageListItemViews) view.getTag(); SipMessage msg = new SipMessage(cursor); String number = msg.getRemoteNumber(); long date = msg.getDate(); String subject = msg.getBodyContent(); String errorTxt = msg.getErrorContent(); String mimeType = msg.getMimeType(); int type = msg.getType(); String timestamp = ""; if (System.currentTimeMillis() - date > 1000 * 60 * 60 * 24) { // If it was received one day ago or more display relative // timestamp - SMS like behavior int flags = DateUtils.FORMAT_ABBREV_RELATIVE; timestamp = (String) DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags); } else {//ww w . j a va 2s . c om // If it has been received recently show time of reception - IM // like behavior timestamp = dateFormatter.format(new Date(date)); } tagView.dateView.setText(timestamp); // Delivery state if (type == SipMessage.MESSAGE_TYPE_QUEUED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_email_pending); tagView.deliveredIndicator.setContentDescription(mContext.getString(R.string.status_pending)); } else if (type == SipMessage.MESSAGE_TYPE_FAILED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_sms_mms_not_delivered); tagView.deliveredIndicator .setContentDescription(mContext.getString(R.string.undelivered_msg_dialog_title)); } else { tagView.deliveredIndicator.setVisibility(View.GONE); tagView.deliveredIndicator.setContentDescription(""); } if (TextUtils.isEmpty(errorTxt)) { tagView.errorView.setVisibility(View.GONE); } else { tagView.errorView.setVisibility(View.VISIBLE); tagView.errorView.setText(errorTxt); } // Subject tagView.contentView.setText(formatMessage(number, subject, mimeType)); if (msg.isOutgoing()) { setPhotoSide(tagView, ArrowPosition.LEFT); // Photo tagView.quickContactView.assignContactUri(personalInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); } else { setPhotoSide(tagView, ArrowPosition.RIGHT); // Contact CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, msg.getFullFrom()); // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); } }
From source file:gov.wa.wsdot.android.wsdot.service.MountainPassesSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;/*from www .j a va 2 s . c o m*/ long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "mountain_passes" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); buildWeatherPhrases(); try { URL url = new URL(MOUNTAIN_PASS_URL); URLConnection urlConn = url.openConnection(); BufferedInputStream bis = new BufferedInputStream(urlConn.getInputStream()); GZIPInputStream gzin = new GZIPInputStream(bis); InputStreamReader is = new InputStreamReader(gzin); BufferedReader in = new BufferedReader(is); String mDateUpdated = ""; String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("GetMountainPassConditionsResult"); JSONArray passConditions = result.getJSONArray("PassCondition"); String weatherCondition; Integer weather_image; Integer forecast_weather_image; List<ContentValues> passes = new ArrayList<ContentValues>(); int numConditions = passConditions.length(); for (int j = 0; j < numConditions; j++) { JSONObject pass = passConditions.getJSONObject(j); ContentValues passData = new ContentValues(); weatherCondition = pass.getString("WeatherCondition"); weather_image = getWeatherImage(weatherPhrases, weatherCondition); String tempDate = pass.getString("DateUpdated"); try { tempDate = tempDate.replace("[", ""); tempDate = tempDate.replace("]", ""); String[] a = tempDate.split(","); StringBuilder sb = new StringBuilder(); for (int m = 0; m < 5; m++) { sb.append(a[m]); sb.append(","); } tempDate = sb.toString().trim(); tempDate = tempDate.substring(0, tempDate.length() - 1); Date date = parseDateFormat.parse(tempDate); mDateUpdated = displayDateFormat.format(date); } catch (Exception e) { Log.e(DEBUG_TAG, "Error parsing date: " + tempDate, e); mDateUpdated = "N/A"; } JSONArray forecasts = pass.getJSONArray("Forecast"); JSONArray forecastItems = new JSONArray(); int numForecasts = forecasts.length(); for (int l = 0; l < numForecasts; l++) { JSONObject forecast = forecasts.getJSONObject(l); if (isNight(forecast.getString("Day"))) { forecast_weather_image = getWeatherImage(weatherPhrasesNight, forecast.getString("ForecastText")); } else { forecast_weather_image = getWeatherImage(weatherPhrases, forecast.getString("ForecastText")); } forecast.put("weather_icon", forecast_weather_image); if (l == 0) { if (weatherCondition.equals("")) { weatherCondition = forecast.getString("ForecastText").split("\\.")[0] + "."; weather_image = forecast_weather_image; } } forecastItems.put(forecast); } passData.put(MountainPasses.MOUNTAIN_PASS_ID, pass.getString("MountainPassId")); passData.put(MountainPasses.MOUNTAIN_PASS_NAME, pass.getString("MountainPassName")); passData.put(MountainPasses.MOUNTAIN_PASS_WEATHER_ICON, weather_image); passData.put(MountainPasses.MOUNTAIN_PASS_FORECAST, forecastItems.toString()); passData.put(MountainPasses.MOUNTAIN_PASS_WEATHER_CONDITION, weatherCondition); passData.put(MountainPasses.MOUNTAIN_PASS_DATE_UPDATED, mDateUpdated); passData.put(MountainPasses.MOUNTAIN_PASS_CAMERA, pass.getString("Cameras")); passData.put(MountainPasses.MOUNTAIN_PASS_ELEVATION, pass.getString("ElevationInFeet")); passData.put(MountainPasses.MOUNTAIN_PASS_TRAVEL_ADVISORY_ACTIVE, pass.getString("TravelAdvisoryActive")); passData.put(MountainPasses.MOUNTAIN_PASS_ROAD_CONDITION, pass.getString("RoadCondition")); passData.put(MountainPasses.MOUNTAIN_PASS_TEMPERATURE, pass.getString("TemperatureInFahrenheit")); JSONObject restrictionOne = pass.getJSONObject("RestrictionOne"); passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_ONE, restrictionOne.getString("RestrictionText")); passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_ONE_DIRECTION, restrictionOne.getString("TravelDirection")); JSONObject restrictionTwo = pass.getJSONObject("RestrictionTwo"); passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_TWO, restrictionTwo.getString("RestrictionText")); passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_TWO_DIRECTION, restrictionTwo.getString("TravelDirection")); if (starred.contains(Integer.parseInt(pass.getString("MountainPassId")))) { passData.put(MountainPasses.MOUNTAIN_PASS_IS_STARRED, 1); } passes.add(passData); } // Purge existing mountain passes covered by incoming data resolver.delete(MountainPasses.CONTENT_URI, null, null); // Bulk insert all the new mountain passes resolver.bulkInsert(MountainPasses.CONTENT_URI, passes.toArray(new ContentValues[passes.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "mountain_passes" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.MOUNTAIN_PASSES_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:com.appjma.appdeployer.adapter.AppVersionsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder holder = (ViewHolder) view.getTag(); String version = cursor.getString(PROJECTION_VERSION); long updatedAt = cursor.getLong(PROJECTION_UPDATED_AT); long id = cursor.getLong(PROJECTION_APP_VERSION_ID); String downloadManagerId = cursor.getString(PROJECTION_DOWNLOAD_MANAGER_ID); int status = -1; if (downloadManagerId != null) { DownloadItem downloadItem = mMap.get(downloadManagerId); if (downloadItem != null) { status = downloadItem.mStatus; }//w w w. j a va 2s.co m } if (status == DownloadManager.STATUS_PENDING || status == DownloadManager.STATUS_RUNNING) { holder.mButton.setBackgroundResource(R.drawable.ic_list_item_downloading); } else if (status == DownloadManager.STATUS_SUCCESSFUL) { holder.mButton.setBackgroundResource(R.drawable.ic_list_item_downloaded); } else { holder.mButton.setBackgroundResource(R.drawable.ic_list_item_download); } holder.mPosition = cursor.getPosition(); holder.mText1.setText(String.format(mVersionFormat, version)); CharSequence updatedAtText = DateUtils.getRelativeTimeSpanString(updatedAt, mNow, DateUtils.MINUTE_IN_MILLIS); holder.mText2.setText(updatedAtText); holder.mId = id; }
From source file:com.nextgis.firereporter.ReporterService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "Received start id " + startId + ": " + intent); super.onStartCommand(intent, flags, startId); if (intent == null) return START_STICKY; String action = intent.getAction(); if (action.equals(ACTION_STOP)) { this.stopSelf(); } else if (action.equals(ACTION_START)) { Log.d(TAG, "Action " + ACTION_START); Context c = this.getApplicationContext(); SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES, MODE_PRIVATE | MODE_MULTI_PROCESS); long nMinTimeBetweenSend = prefs.getLong(SettingsActivity.KEY_PREF_INTERVAL + "_long", DateUtils.MINUTE_IN_MILLIS); boolean bBattEconomy = prefs.getBoolean(SettingsActivity.KEY_PREF_SERVICE_BATT_SAVE, true); if (!HttpGetter.IsNetworkAvailible(c)) { ScheduleNextUpdate(c, nMinTimeBetweenSend, bBattEconomy); Log.d(TAG, "network not availible"); return START_NOT_STICKY; }/*from www .j ava 2 s . co m*/ Cursor cursor = ReportsDB.query(ReportsDatabase.TABLE_POS, null, null, null, null, null, null); Log.d(TAG, "record count = " + cursor.getCount()); if (cursor.getCount() < 1) { this.stopSelf(); return START_NOT_STICKY; } if (fireDataSender == null) { Log.d(TAG, "new fireDataSender"); fireDataSender = new SendFireDataTask(); fireDataSender.execute(this.getApplicationContext()); ScheduleNextUpdate(c, nMinTimeBetweenSend, bBattEconomy); } else if (fireDataSender.getStatus() == AsyncTask.Status.FINISHED) { Log.d(TAG, "exist fireDataSender"); fireDataSender.execute(this.getApplicationContext()); ScheduleNextUpdate(c, nMinTimeBetweenSend, bBattEconomy); } else if (fireDataSender.getStatus() == AsyncTask.Status.PENDING || fireDataSender.getStatus() == AsyncTask.Status.RUNNING) { Log.d(TAG, "exist fireDataSender executing"); ScheduleNextUpdate(c, nMinTimeBetweenSend, bBattEconomy); } else { Log.d(TAG, "unexpected behaviour"); this.stopSelf(); } } return START_NOT_STICKY; }
From source file:de.aw.awlib.gv.CalendarReminder.java
/** * Erstellt ContentValues fuer einen Event im ausgewaehlten Calendar * * @param calendarID// ww w . ja v a2 s . c o m * ID des ausgewaehlten Kalenders * @param start * Startdatum des Events * @param dauer * Dauer des Events in Minuten * @param title * Title des Events * @param body * Body des Events (optional) * @return die ID des eingefuegten Events. -1, wenn ein Fehler aufgetreten ist. */ private ContentValues createEventValues(long calendarID, @NonNull Date start, long dauer, @NonNull String title, @Nullable String body) { ContentValues values = new ContentValues(); values.put(Events.CUSTOM_APP_PACKAGE, mContext.getPackageName()); values.put(Events.DTSTART, start.getTime()); values.put(Events.DTEND, start.getTime() + DateUtils.MINUTE_IN_MILLIS * dauer); values.put(Events.TITLE, title); if (body != null) { values.put(Events.DESCRIPTION, body); } values.put(Events.CALENDAR_ID, calendarID); values.put(Events.EVENT_TIMEZONE, Locale.getDefault().getDisplayName()); return values; }
From source file:com.todoroo.astrid.notes.CommentsController.java
/** Helper method to set the contents and visibility of each field */ private void bindView(View view, NoteOrUpdate item) { // name/*from w w w. j ava 2 s . c om*/ final TextView nameView = (TextView) view.findViewById(R.id.title); { nameView.setText(item.title); Linkify.addLinks(nameView, Linkify.ALL); } // date final TextView date = (TextView) view.findViewById(R.id.date); { CharSequence dateString = DateUtils.getRelativeTimeSpanString(item.createdAt, DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); date.setText(dateString); } // picture final ImageView commentPictureView = (ImageView) view.findViewById(R.id.comment_picture); setupImagePopupForCommentView(view, commentPictureView, item.commentBitmap, activity); }
From source file:com.appsimobile.appsii.module.weather.WeatherLoadingService.java
/** * Returns true when the interval to request a sync has been expired. * Normally this is determined in the sync adapter mechanism itself. * But if it decides to stop syncing correctly, this method can * determine if now would be a good time to call * {@link ContentResolver#requestSync(Account, String, Bundle)} to * make sure the weather data is up to date. * <p/>//from w w w .j av a 2 s. c o m * Returns true when now is a good time to update the weatherdata. */ public static boolean hasTimeoutExpired(SharedPreferences preferences) { long lastUpdate = preferences.getLong(PREFERENCE_LAST_UPDATED_MILLIS, 0); long timePassedMillis = System.currentTimeMillis() - lastUpdate; long minutesPassed = timePassedMillis / DateUtils.MINUTE_IN_MILLIS; return minutesPassed > 45; }
From source file:com.ayuget.redface.job.PrivateMessagesService.java
@TargetApi(android.os.Build.VERSION_CODES.KITKAT) @Override/* w w w .jav a 2 s . com*/ protected void onHandleIntent(Intent intent) { Log.d(LOG_TAG, "Handling intent"); if (!settings.arePrivateMessagesNoticationsEnabled()) { return; } final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(getApplicationContext()); for (User redfaceUser : userManager.getRealUsers()) { subscriptions.add(mdService.getNewPrivateMessages(redfaceUser) .subscribe(new EndlessObserver<List<PrivateMessage>>() { @Override public void onNext(List<PrivateMessage> privateMessages) { for (PrivateMessage privateMessage : privateMessages) { // Prepare intent to deal with clicks Intent resultIntent = new Intent(PrivateMessagesService.this, PrivateMessagesActivity.class); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); resultIntent.putExtra(UIConstants.ARG_SELECTED_PM, privateMessage); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder( getApplicationContext()).setSmallIcon(R.drawable.ic_action_emo_wonder) .setColor(getResources().getColor(R.color.theme_primary)) .setContentTitle(privateMessage.getRecipient()) .setContentText(privateMessage.getSubject()) .setContentIntent(resultPendingIntent).setAutoCancel(true); builder.setVibrate(VIBRATION_PATTERN); notificationManager.notify((int) privateMessage.getId(), builder.build()); } } })); } // Setup next alarm long wakeUpTime = System.currentTimeMillis() + settings.getPrivateMessagesPollingFrequency() * DateUtils.MINUTE_IN_MILLIS; AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, PrivateMessagesService.class); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); Log.d(LOG_TAG, "Going to sleep, setting wake-up alarm to: " + wakeUpTime); if (AndroidUtils.isKitKatOrHigher()) { am.setExact(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } else { am.set(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } }