List of usage examples for android.content ContentValues getAsString
public String getAsString(String key)
From source file:com.example.android.sunshine.data.FetchWeatherTask.java
String[] convertContentValuesToUXFormat(Vector<ContentValues> cvv) { // return strings to keep UI functional for now String[] resultStrs = new String[cvv.size()]; for (int i = 0; i < cvv.size(); i++) { ContentValues weatherValues = cvv.elementAt(i); String highAndLow = formatHighLows( weatherValues.getAsDouble(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP), weatherValues.getAsDouble(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP)); resultStrs[i] = getReadableDateString(weatherValues.getAsLong(WeatherContract.WeatherEntry.COLUMN_DATE)) + " - " + weatherValues.getAsString(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC) + " - " + highAndLow;//from w w w . j a v a 2 s.com } return resultStrs; }
From source file:com.iyedb.sunshine.FetchWeatherTask.java
@Override protected Void doInBackground(String... params) { Log.d(LOG_TAG, "in doInBackground"); // If there's no zip code, there's nothing to look up. Verify size of params. if (params.length == 0) { return null; }/* w w w . ja va 2 s . c o m*/ String locationParam = params[0]; Log.d(LOG_TAG, "getting weather data for " + locationParam); // These two need to be declared outside the try/catch // so that they can be closed in the finally block. HttpURLConnection urlConnection = null; BufferedReader reader = null; // Will contain the raw JSON response as a string. String forecastJsonStr = null; String format = "json"; String units = "metric"; int numDays = 14; try { // Construct the URL for the OpenWeatherMap query // Possible parameters are avaiable at OWM's forecast API page, at // http://openweathermap.org/API#forecast final String FORECAST_BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/daily?"; final String QUERY_PARAM = "q"; final String FORMAT_PARAM = "mode"; final String UNITS_PARAM = "units"; final String DAYS_PARAM = "cnt"; Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon().appendQueryParameter(QUERY_PARAM, params[0]) .appendQueryParameter(FORMAT_PARAM, format).appendQueryParameter(UNITS_PARAM, units) .appendQueryParameter(DAYS_PARAM, Integer.toString(numDays)).build(); URL url = new URL(builtUri.toString()); // Create the request to OpenWeatherMap, and open the connection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); // Read the input stream into a String InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) { // Nothing to do. return null; } reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { // Since it's JSON, adding a newline isn't necessary (it won't affect parsing) // But it does make debugging a *lot* easier if you print out the completed // buffer for debugging. buffer.append(line + "\n"); } if (buffer.length() == 0) { // Stream was empty. No point in parsing. return null; } forecastJsonStr = buffer.toString(); } catch (IOException e) { Log.e(LOG_TAG, "Error ", e); // If the code didn't successfully get the weather data, there's no point in attemping // to parse it. return null; } finally { if (urlConnection != null) { urlConnection.disconnect(); } if (reader != null) { try { reader.close(); } catch (final IOException e) { Log.e(LOG_TAG, "Error closing stream", e); } } } try { getWeatherDataFromJson(forecastJsonStr, numDays, locationParam); if (DEBUG) { Cursor cursor = mContext .getContentResolver().query( WeatherEntry.CONTENT_URI, new String[] { WeatherEntry._ID, WeatherEntry.COLUMN_LOC_KEY, WeatherEntry.COLUMN_WEATHER_ID }, null, null, null); Log.d(LOG_TAG, "Weather table contents:"); while (cursor.moveToNext()) { ContentValues resultValues = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, resultValues); StringBuilder stringBuilder = new StringBuilder(); for (String key : resultValues.keySet()) { stringBuilder.append(key).append(':').append(resultValues.getAsString(key)).append('|'); } Log.v(LOG_TAG, stringBuilder.toString()); } Cursor cursorLoc = mContext.getContentResolver() .query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID, LocationEntry.COLUMN_LOCATION_SETTING, LocationEntry.COLUMN_CITY_NAME }, null, null, null); Log.d(LOG_TAG, "Location table contents:"); while (cursorLoc.moveToNext()) { ContentValues resultValues = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursorLoc, resultValues); StringBuilder stringBuilder = new StringBuilder(); for (String key : resultValues.keySet()) { stringBuilder.append(key).append(':').append(resultValues.getAsString(key)).append('|'); } Log.v(LOG_TAG, stringBuilder.toString()); } } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } // This will only happen if there was an error getting or parsing the forecast. return null; }
From source file:com.akop.bach.parser.PsnParser.java
public void createAccount(BasicAccount account, ContentValues cv) { // Add profile to database ContentResolver cr = mContext.getContentResolver(); cr.insert(Profiles.CONTENT_URI, cv); cr.notifyChange(Profiles.CONTENT_URI, null); PsnAccount psnAccount = (PsnAccount) account; // Save changes to preferences psnAccount.setOnlineId(cv.getAsString(Profiles.ONLINE_ID)); psnAccount.setIconUrl(cv.getAsString(Profiles.ICON_URL)); psnAccount.setLastSummaryUpdate(System.currentTimeMillis()); account.save(Preferences.get(mContext)); }
From source file:watch.oms.omswatch.parser.OMSConfigDBParser.java
private boolean validateRowData(ContentValues pContentValues) { boolean result = true; String usidValue = pContentValues.getAsString(OMSDatabaseConstants.UNIQUE_ROW_ID); if (usidValue != null && usidValue.equals(OMSConstants.NULL_STRING)) { result = false;//from w ww . ja va 2 s .c o m return result; } //Commented the below code to get update in local db if the record is soft deleted in server. /*String isDeleteValue = pContentValues .getAsString(OMSDatabaseConstants.IS_DELETE); if (isDeleteValue != null && isDeleteValue.equals(OMSConstants.IS_DELETE_ONE)) { result = false; }*/ return result; }
From source file:com.hybris.mobile.lib.commerce.provider.CatalogProvider.java
@Override public Uri insert(Uri uri, ContentValues values) { switch (URI_MATCHER.match(uri)) { // Insert a group link case CatalogContract.Provider.CODE_GROUP_ID: Log.i(TAG, "Saving the information for the item " + values.getAsString(CatalogContract.DataBaseDataLinkGroup.ATT_DATA_ID)); try {// ww w . j ava 2 s . c o m mDatabaseHelper.getWritableDatabase() .insertOrThrow(CatalogContract.DataBaseDataLinkGroup.TABLE_NAME, null, values); } catch (SQLiteConstraintException e) { Log.i(TAG, "Item " + values.getAsString(CatalogContract.DataBaseDataLinkGroup.ATT_DATA_ID) + "|" + values.getAsString(CatalogContract.DataBaseDataLinkGroup.ATT_GROUP_ID) + " already exists, nothing to do"); } break; // Insert or update for the rest case CatalogContract.Provider.CODE_DATA_ID: case CatalogContract.Provider.CODE_DATA_DETAILS_ID: case CatalogContract.Provider.CODE_SYNC_GROUP: insertOrUpdate(uri, values); break; default: Log.e(TAG, "URI not recognized" + uri.toString()); throw new IllegalArgumentException("URI not recognized" + uri.toString()); } Log.i(TAG, "Notify changes for " + uri); // Notify watchers of the change getContext().getContentResolver().notifyChange(uri, null); return uri; }
From source file:com.granita.icloudcalsync.resource.LocalCalendar.java
protected void populateEvent(Event e, ContentValues values) { e.setUid(values.getAsString(entryColumnUID())); e.setSummary(values.getAsString(Events.TITLE)); e.setLocation(values.getAsString(Events.EVENT_LOCATION)); e.setDescription(values.getAsString(Events.DESCRIPTION)); final boolean allDay = values.getAsInteger(Events.ALL_DAY) != 0; final long tsStart = values.getAsLong(Events.DTSTART); final String duration = values.getAsString(Events.DURATION); String tzId = null;/*from ww w . j a va2 s. c om*/ Long tsEnd = values.getAsLong(Events.DTEND); if (allDay) { e.setDtStart(tsStart, null); if (tsEnd == null) { Dur dur = new Dur(duration); java.util.Date dEnd = dur.getTime(new java.util.Date(tsStart)); tsEnd = dEnd.getTime(); } e.setDtEnd(tsEnd, null); } else { // use the start time zone for the end time, too // because apps like Samsung Planner allow the user to change "the" time zone but change the start time zone only tzId = values.getAsString(Events.EVENT_TIMEZONE); e.setDtStart(tsStart, tzId); if (tsEnd != null) e.setDtEnd(tsEnd, tzId); else if (!StringUtils.isEmpty(duration)) e.setDuration(new Duration(new Dur(duration))); } // recurrence try { String strRRule = values.getAsString(Events.RRULE); if (!StringUtils.isEmpty(strRRule)) e.setRrule(new RRule(strRRule)); String strRDate = values.getAsString(Events.RDATE); if (!StringUtils.isEmpty(strRDate)) { RDate rDate = new RDate(); rDate.setValue(strRDate); e.getRdates().add(rDate); } String strExRule = values.getAsString(Events.EXRULE); if (!StringUtils.isEmpty(strExRule)) { ExRule exRule = new ExRule(); exRule.setValue(strExRule); e.setExrule(exRule); } String strExDate = values.getAsString(Events.EXDATE); if (!StringUtils.isEmpty(strExDate)) { // always empty, see https://code.google.com/p/android/issues/detail?id=172411 ExDate exDate = new ExDate(); exDate.setValue(strExDate); e.getExdates().add(exDate); } } catch (ParseException ex) { Log.w(TAG, "Couldn't parse recurrence rules, ignoring", ex); } catch (IllegalArgumentException ex) { Log.w(TAG, "Invalid recurrence rules, ignoring", ex); } if (values.containsKey(Events.ORIGINAL_INSTANCE_TIME)) { // this event is an exception of a recurring event long originalInstanceTime = values.getAsLong(Events.ORIGINAL_INSTANCE_TIME); boolean originalAllDay = values.getAsInteger(Events.ORIGINAL_ALL_DAY) != 0; Date originalDate = originalAllDay ? new Date(originalInstanceTime) : new DateTime(originalInstanceTime); if (originalDate instanceof DateTime) ((DateTime) originalDate).setUtc(true); e.setRecurrenceId(new RecurrenceId(originalDate)); } // status if (values.containsKey(Events.STATUS)) switch (values.getAsInteger(Events.STATUS)) { case Events.STATUS_CONFIRMED: e.setStatus(Status.VEVENT_CONFIRMED); break; case Events.STATUS_TENTATIVE: e.setStatus(Status.VEVENT_TENTATIVE); break; case Events.STATUS_CANCELED: e.setStatus(Status.VEVENT_CANCELLED); } // availability e.setOpaque(values.getAsInteger(Events.AVAILABILITY) != Events.AVAILABILITY_FREE); // set ORGANIZER only when there are attendees if (values.getAsInteger(Events.HAS_ATTENDEE_DATA) != 0 && values.containsKey(Events.ORGANIZER)) try { e.setOrganizer(new Organizer(new URI("mailto", values.getAsString(Events.ORGANIZER), null))); } catch (URISyntaxException ex) { Log.e(TAG, "Error when creating ORGANIZER URI, ignoring", ex); } // classification switch (values.getAsInteger(Events.ACCESS_LEVEL)) { case Events.ACCESS_CONFIDENTIAL: case Events.ACCESS_PRIVATE: e.setForPublic(false); break; case Events.ACCESS_PUBLIC: e.setForPublic(true); } }
From source file:org.hfoss.posit.android.web.Communicator.java
public boolean sendFind(Find find, String action) { boolean success = false; String url;// ww w .jav a 2 s . co m HashMap<String, String> sendMap = find.getContentMapGuid(); // Log.i(TAG, "sendFind map = " + sendMap.toString()); cleanupOnSend(sendMap); sendMap.put("imei", imei); String guid = sendMap.get(PositDbHelper.FINDS_GUID); long id = find.getId(); // Create the url if (action.equals("create")) { url = server + "/api/createFind?authKey=" + authKey; } else { url = server + "/api/updateFind?authKey=" + authKey; } if (Utils.debug) { Log.i(TAG, "SendFind=" + sendMap.toString()); } // Send the find try { responseString = doHTTPPost(url, sendMap); } catch (Exception e) { Log.i(TAG, e.getMessage()); Utils.showToast(mContext, e.getMessage()); return false; } if (Utils.debug) Log.i(TAG, "sendFind.ResponseString: " + responseString); // If the update failed return false if (responseString.indexOf("True") == -1) { Log.i(TAG, "sendFind result doesn't contain 'True'"); return false; } else { PositDbHelper dbh = new PositDbHelper(mContext); success = dbh.markFindSynced(id); if (Utils.debug) Log.i(TAG, "sendfind synced " + id + " " + success); } if (success) { // Otherwise send the Find's images //long id = Long.parseLong(sendMap.get(PositDbHelper.FINDS_ID)); PositDbHelper dbh = new PositDbHelper(mContext); ArrayList<ContentValues> photosList = dbh.getImagesListSinceUpdate(id, projectId); Log.i(TAG, "sendFind, photosList=" + photosList.toString()); Iterator<ContentValues> it = photosList.listIterator(); while (it.hasNext()) { ContentValues imageData = it.next(); Uri uri = Uri.parse(imageData.getAsString(PositDbHelper.PHOTOS_IMAGE_URI)); String base64Data = convertUriToBase64(uri); uri = Uri.parse(imageData.getAsString(PositDbHelper.PHOTOS_THUMBNAIL_URI)); String base64Thumbnail = convertUriToBase64(uri); sendMap = new HashMap<String, String>(); sendMap.put(COLUMN_IMEI, Utils.getIMEI(mContext)); sendMap.put(PositDbHelper.FINDS_GUID, guid); sendMap.put(PositDbHelper.PHOTOS_IDENTIFIER, imageData.getAsString(PositDbHelper.PHOTOS_IDENTIFIER)); sendMap.put(PositDbHelper.FINDS_PROJECT_ID, imageData.getAsString(PositDbHelper.FINDS_PROJECT_ID)); sendMap.put(PositDbHelper.FINDS_TIME, imageData.getAsString(PositDbHelper.FINDS_TIME)); sendMap.put(PositDbHelper.PHOTOS_MIME_TYPE, imageData.getAsString(PositDbHelper.PHOTOS_MIME_TYPE)); sendMap.put("mime_type", "image/jpeg"); sendMap.put(PositDbHelper.PHOTOS_DATA_FULL, base64Data); sendMap.put(PositDbHelper.PHOTOS_DATA_THUMBNAIL, base64Thumbnail); sendMedia(sendMap); } } // Update the Synced attribute. return success; }
From source file:com.granita.icloudcalsync.resource.LocalCalendar.java
void populateAttendee(Event event, ContentValues values) throws RemoteException { try {/*from w ww .j a v a2 s .c om*/ Attendee attendee = new Attendee(new URI("mailto", values.getAsString(Attendees.ATTENDEE_EMAIL), null)); ParameterList params = attendee.getParameters(); String cn = values.getAsString(Attendees.ATTENDEE_NAME); if (cn != null) params.add(new Cn(cn)); // type int type = values.getAsInteger(Attendees.ATTENDEE_TYPE); params.add((type == Attendees.TYPE_RESOURCE) ? CuType.RESOURCE : CuType.INDIVIDUAL); // role int relationship = values.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP); switch (relationship) { case Attendees.RELATIONSHIP_ORGANIZER: params.add(Role.CHAIR); break; case Attendees.RELATIONSHIP_ATTENDEE: case Attendees.RELATIONSHIP_PERFORMER: case Attendees.RELATIONSHIP_SPEAKER: params.add((type == Attendees.TYPE_REQUIRED) ? Role.REQ_PARTICIPANT : Role.OPT_PARTICIPANT); break; case Attendees.RELATIONSHIP_NONE: params.add(Role.NON_PARTICIPANT); } // status switch (values.getAsInteger(Attendees.ATTENDEE_STATUS)) { case Attendees.ATTENDEE_STATUS_INVITED: params.add(PartStat.NEEDS_ACTION); break; case Attendees.ATTENDEE_STATUS_ACCEPTED: params.add(PartStat.ACCEPTED); break; case Attendees.ATTENDEE_STATUS_DECLINED: params.add(PartStat.DECLINED); break; case Attendees.ATTENDEE_STATUS_TENTATIVE: params.add(PartStat.TENTATIVE); break; } event.getAttendees().add(attendee); } catch (URISyntaxException ex) { Log.e(TAG, "Couldn't parse attendee information, ignoring", ex); } }
From source file:at.bitfire.davdroid.resource.LocalCalendar.java
protected void populateEvent(Event e, ContentValues values) { e.setUid(values.getAsString(entryColumnUID())); e.summary = values.getAsString(Events.TITLE); e.location = values.getAsString(Events.EVENT_LOCATION); e.description = values.getAsString(Events.DESCRIPTION); final boolean allDay = values.getAsInteger(Events.ALL_DAY) != 0; final long tsStart = values.getAsLong(Events.DTSTART); final String duration = values.getAsString(Events.DURATION); String tzId;// w w w . j a va2 s . c o m Long tsEnd = values.getAsLong(Events.DTEND); if (allDay) { e.setDtStart(tsStart, null); if (tsEnd == null) { Dur dur = new Dur(duration); java.util.Date dEnd = dur.getTime(new java.util.Date(tsStart)); tsEnd = dEnd.getTime(); } e.setDtEnd(tsEnd, null); } else { // use the start time zone for the end time, too // because apps like Samsung Planner allow the user to change "the" time zone but change the start time zone only tzId = values.getAsString(Events.EVENT_TIMEZONE); e.setDtStart(tsStart, tzId); if (tsEnd != null) e.setDtEnd(tsEnd, tzId); else if (!StringUtils.isEmpty(duration)) e.duration = new Duration(new Dur(duration)); } // recurrence try { String strRRule = values.getAsString(Events.RRULE); if (!StringUtils.isEmpty(strRRule)) e.rrule = new RRule(strRRule); String strRDate = values.getAsString(Events.RDATE); if (!StringUtils.isEmpty(strRDate)) { RDate rDate = (RDate) DateUtils.androidStringToRecurrenceSet(strRDate, RDate.class, allDay); e.getRdates().add(rDate); } String strExRule = values.getAsString(Events.EXRULE); if (!StringUtils.isEmpty(strExRule)) { ExRule exRule = new ExRule(); exRule.setValue(strExRule); e.exrule = exRule; } String strExDate = values.getAsString(Events.EXDATE); if (!StringUtils.isEmpty(strExDate)) { ExDate exDate = (ExDate) DateUtils.androidStringToRecurrenceSet(strExDate, ExDate.class, allDay); e.getExdates().add(exDate); } } catch (ParseException ex) { Log.w(TAG, "Couldn't parse recurrence rules, ignoring", ex); } catch (IllegalArgumentException ex) { Log.w(TAG, "Invalid recurrence rules, ignoring", ex); } if (values.containsKey(Events.ORIGINAL_INSTANCE_TIME)) { // this event is an exception of a recurring event long originalInstanceTime = values.getAsLong(Events.ORIGINAL_INSTANCE_TIME); boolean originalAllDay = false; if (values.containsKey(Events.ORIGINAL_ALL_DAY)) originalAllDay = values.getAsInteger(Events.ORIGINAL_ALL_DAY) != 0; Date originalDate = originalAllDay ? new Date(originalInstanceTime) : new DateTime(originalInstanceTime); if (originalDate instanceof DateTime) ((DateTime) originalDate).setUtc(true); e.recurrenceId = new RecurrenceId(originalDate); } // status if (values.containsKey(Events.STATUS)) switch (values.getAsInteger(Events.STATUS)) { case Events.STATUS_CONFIRMED: e.status = Status.VEVENT_CONFIRMED; break; case Events.STATUS_TENTATIVE: e.status = Status.VEVENT_TENTATIVE; break; case Events.STATUS_CANCELED: e.status = Status.VEVENT_CANCELLED; } // availability e.opaque = values.getAsInteger(Events.AVAILABILITY) != Events.AVAILABILITY_FREE; // set ORGANIZER if there's attendee data if (values.getAsInteger(Events.HAS_ATTENDEE_DATA) != 0) try { e.organizer = new Organizer(new URI("mailto", values.getAsString(Events.ORGANIZER), null)); } catch (URISyntaxException ex) { Log.e(TAG, "Error when creating ORGANIZER mailto URI, ignoring", ex); } // classification switch (values.getAsInteger(Events.ACCESS_LEVEL)) { case Events.ACCESS_CONFIDENTIAL: case Events.ACCESS_PRIVATE: e.forPublic = false; break; case Events.ACCESS_PUBLIC: e.forPublic = true; } }
From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java
private void syncNotifications(Account account, SyncResult syncResult) throws AuthenticationException, IOException { final User user = AccountUtils.getUser(getContext(), account.name); final String notificationReply = SifeupAPI.getReply(SifeupAPI.getNotificationsUrl(user.getUserCode()), account, getContext());// w w w . j av a2s . c om final Gson gson = GsonUtils.getGson(); final Notification[] notifications = gson.fromJson(notificationReply, Notification[].class); if (notifications == null) { syncResult.stats.numParseExceptions++; LogUtils.trackException(getContext(), new RuntimeException(), notificationReply, true); return; } ArrayList<String> fetchedNotCodes = new ArrayList<String>(); ArrayList<ContentValues> bulkValues = new ArrayList<ContentValues>(); for (Notification not : notifications) { final ContentValues values = new ContentValues(); values.put(SigarraContract.Notifcations.CONTENT, gson.toJson(not)); fetchedNotCodes.add(not.getCode()); if (getContext().getContentResolver().update(SigarraContract.Notifcations.CONTENT_URI, values, SigarraContract.Notifcations.UPDATE_NOTIFICATION, SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, not.getCode())) == 0) { values.put(SigarraContract.Notifcations.CODE, account.name); values.put(SigarraContract.Notifcations.ID_NOTIFICATION, not.getCode()); values.put(SigarraContract.Notifcations.STATE, SigarraContract.Notifcations.NEW); values.put(SigarraContract.Notifcations.CODE, account.name); bulkValues.add(values); } } // inserting the values if (bulkValues.size() > 0) { getContext().getContentResolver().bulkInsert(SigarraContract.Notifcations.CONTENT_URI, bulkValues.toArray(new ContentValues[0])); // if the account being synced is the current active accout // display notification if (AccountUtils.getActiveUserName(getContext()).equals(account.name)) { final NotificationManager mNotificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getContext()); notBuilder.setAutoCancel(true).setOnlyAlertOnce(true) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); if (bulkValues.size() == 1) { final Notification notification = gson.fromJson( bulkValues.get(0).getAsString(SigarraContract.Notifcations.CONTENT), Notification.class); Intent notifyIntent = new Intent(getContext(), NotificationsDescActivity.class) .putExtra(NotificationsDescFragment.NOTIFICATION, notification); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); notBuilder.setSmallIcon(R.drawable.icon).setTicker(notification.getMessage()) .setContentTitle(notification.getSubject()).setContentText(notification.getMessage()) .setContentIntent(notifyPendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage()) .setBigContentTitle(notification.getSubject()) .setSummaryText(notification.getMessage())); mNotificationManager.notify(notification.getCode().hashCode(), notBuilder.build()); } else { final String notTitle = getContext().getString(R.string.new_notifications, bulkValues.size()); Intent notifyIntent = new Intent(getContext(), NotificationsActivity.class); // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // Sets a title for the Inbox style big view inboxStyle.setBigContentTitle(notTitle); // Moves events into the big view for (ContentValues value : bulkValues) { final Notification notification = gson.fromJson( value.getAsString(SigarraContract.Notifcations.CONTENT), Notification.class); inboxStyle.addLine(notification.getSubject()); } // Moves the big view style object into the notification // object. notBuilder.setStyle(inboxStyle); notBuilder.setSmallIcon(R.drawable.icon).setTicker(notTitle).setContentTitle(notTitle) .setContentText("").setContentIntent(notifyPendingIntent); mNotificationManager.notify(NotificationsFragment.class.getName().hashCode(), notBuilder.build()); } } } final Cursor syncState = getContext().getContentResolver().query(SigarraContract.LastSync.CONTENT_URI, SigarraContract.LastSync.COLUMNS, SigarraContract.LastSync.PROFILE, SigarraContract.LastSync.getLastSyncSelectionArgs(AccountUtils.getActiveUserName(getContext())), null); try { if (syncState.moveToFirst()) { if (syncState.getLong(syncState.getColumnIndex(SigarraContract.LastSync.NOTIFICATIONS)) == 0) { // Report that we have checked the notifications final ContentValues values = new ContentValues(); values.put(SigarraContract.LastSync.NOTIFICATIONS, System.currentTimeMillis()); getContext().getContentResolver().update(SigarraContract.LastSync.CONTENT_URI, values, SigarraContract.LastSync.PROFILE, SigarraContract.LastSync.getLastSyncSelectionArgs(account.name)); } } } finally { syncState.close(); } ArrayList<String> notToDelete = new ArrayList<String>(); final Cursor cursor = getContext().getContentResolver().query(SigarraContract.Notifcations.CONTENT_URI, new String[] { SigarraContract.Notifcations.ID_NOTIFICATION }, SigarraContract.Notifcations.PROFILE, SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name), null); try { if (cursor.moveToFirst()) { do { final String code = cursor.getString(0); if (!fetchedNotCodes.contains(code)) notToDelete.add(code); } while (cursor.moveToNext()); } else { // no notifications getContext().getContentResolver().notifyChange(SigarraContract.Notifcations.CONTENT_URI, null); } } finally { cursor.close(); } if (notToDelete.size() > 0) getContext().getContentResolver().delete(SigarraContract.Notifcations.CONTENT_URI, SigarraContract.Notifcations.getNotificationsDelete(notToDelete.toArray(new String[0])), SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, notToDelete.toArray(new String[0]))); syncResult.stats.numEntries += notifications.length; }