List of usage examples for android.content ContentValues getAsLong
public Long getAsLong(String key)
From source file:com.roamprocess1.roaming4world.ui.favorites.FavAdapter.java
@Override public void bindView(View view, final Context context, Cursor cursor) { ContentValues cv = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, cv); int type = ContactsWrapper.TYPE_CONTACT; if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) { type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE); }//from www. java2s. com showViewForType(view, type); if (type == ContactsWrapper.TYPE_GROUP) { // Get views TextView tv = (TextView) view.findViewById(R.id.header_text); ImageView icon = (ImageView) view.findViewById(R.id.header_icon); // PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view.findViewById(R.id.header_presence_spinner); // Get datas SipProfile acc = new SipProfile(cursor); final Long profileId = cv.getAsLong(BaseColumns._ID); final String groupName = acc.android_group; final String displayName = acc.display_name; final String wizard = acc.wizard; final boolean publishedEnabled = (acc.publish_enabled == 1); final String domain = acc.getDefaultDomain(); // Bind datas to view //tv.setText(displayName); //Commented by Esstel Softwares tv.setText("Starred Android Contacts"); icon.setImageResource(WizardUtils.getWizardIconRes(wizard)); // presSpinner.setProfileId(profileId); // Extra menu view if not already set ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner); MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled); MenuBuilder menuBuilder; if (menuViewWrapper.getTag() == null) { final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext); mActionMenuPresenter.setReserveOverflow(true); menuBuilder = new MenuBuilder(context); menuBuilder.setCallback(newMcb); MenuInflater inflater = new MenuInflater(context); inflater.inflate(R.menu.fav_menu_new, menuBuilder); menuBuilder.addMenuPresenter(mActionMenuPresenter); ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper); UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null); menuViewWrapper.addView(menuView, layoutParams); menuViewWrapper.setTag(menuBuilder); } else { menuBuilder = (MenuBuilder) menuViewWrapper.getTag(); menuBuilder.setCallback(newMcb); } // menuBuilder.findItem(R.id.share_presence).setTitle(publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing); // menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName)); } else if (type == ContactsWrapper.TYPE_CONTACT) { ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor); ci.userData = cursor.getPosition(); // Get views TextView tv = (TextView) view.findViewById(R.id.contact_name); QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo); TextView statusText = (TextView) view.findViewById(R.id.status_text); ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon); // Bind if (ci.contactId != null) { tv.setText(ci.displayName); badge.assignContactUri(ci.callerInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(), ci.callerInfo, R.drawable.ic_contact_picture_holo_dark); statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE); statusText.setText(ci.status); statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE); statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence)); } View v; v = view.findViewById(R.id.contact_view); v.setTag(ci); v.setOnClickListener(mPrimaryActionListener); v = view.findViewById(R.id.secondary_action_icon); v.setTag(ci); v.setOnClickListener(mSecondaryActionListener); } else if (type == ContactsWrapper.TYPE_CONFIGURE) { // We only bind if it's the correct type // View v = view.findViewById(R.id.configure_view); //v.setOnClickListener(this); //ConfigureObj cfg = new ConfigureObj(); // cfg.profileId = cv.getAsLong(BaseColumns._ID); // v.setTag(cfg); } }
From source file:ch.ethz.twimight.net.opportunistic.ScanningService.java
private void processTweet(JSONObject o) { try {//from w w w .j av a 2s . c o m Log.i(TAG, "processTweet"); ContentValues cvTweet = getTweetCV(o); cvTweet.put(Tweets.COL_BUFFER, Tweets.BUFFER_DISASTER); // we don't enter our own tweets into the DB. if (!cvTweet.getAsLong(Tweets.COL_USER_TID).toString() .equals(LoginActivity.getTwitterId(getApplicationContext()))) { ContentValues cvUser = getUserCV(o); // insert the tweet Uri insertUri = Uri.parse("content://" + Tweets.TWEET_AUTHORITY + "/" + Tweets.TWEETS + "/" + Tweets.TWEETS_TABLE_TIMELINE + "/" + Tweets.TWEETS_SOURCE_DISASTER); getContentResolver().insert(insertUri, cvTweet); // insert the user Uri insertUserUri = Uri.parse( "content://" + TwitterUsers.TWITTERUSERS_AUTHORITY + "/" + TwitterUsers.TWITTERUSERS); getContentResolver().insert(insertUserUri, cvUser); } } catch (JSONException e1) { Log.e(TAG, "Exception while receiving disaster tweet ", e1); } }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Get content by its local identifier.//from ww w . j a v a 2 s. c o m * @param localId the content local identifier. * @return the content if found, null otherwise. */ @SuppressWarnings("unchecked") public <T extends CapptainReachContent> T getContent(long localId) { /* Return content from cache if possible */ CapptainReachContent cachedContent = mContentCache.get(localId); if (cachedContent != null) try { return (T) cachedContent; } catch (ClassCastException cce) { /* Invalid type */ return null; } /* * Otherwise fetch in SQLite: required if the application process has been killed while clicking * on a system notification or while fetching another content than the current one. */ else { /* Fetch from storage */ ContentValues values = mDB.get(localId); if (values != null) try { return (T) parseContent(values); } catch (ClassCastException cce) { /* Invalid type */ } catch (Exception e) { /* * Delete content that cannot be parsed, may be corrupted data, we cannot send "dropped" * feedback as we need the Reach contentId and kind. */ deleteContent(localId, values.getAsLong(DOWNLOAD_ID)); } /* Not found, invalid type or an error occurred */ return null; } }
From source file:org.runnerup.view.DetailActivity.java
void fillHeaderData() { // Fields from the database (projection) // Must include the _id column for the adapter to work String[] from = new String[] { DB.ACTIVITY.START_TIME, DB.ACTIVITY.DISTANCE, DB.ACTIVITY.TIME, DB.ACTIVITY.COMMENT, DB.ACTIVITY.SPORT }; Cursor c = mDB.query(DB.ACTIVITY.TABLE, from, "_id == " + mID, null, null, null, null, null); c.moveToFirst();//from w w w . ja va 2s. c o m ContentValues tmp = DBHelper.get(c); c.close(); long st = 0; if (tmp.containsKey(DB.ACTIVITY.START_TIME)) { st = tmp.getAsLong(DB.ACTIVITY.START_TIME); setTitle("RunnerUp - " + formatter.formatDateTime(Formatter.TXT_LONG, st)); } float d = 0; if (tmp.containsKey(DB.ACTIVITY.DISTANCE)) { d = tmp.getAsFloat(DB.ACTIVITY.DISTANCE); activityDistance.setText(formatter.formatDistance(Formatter.TXT_LONG, (long) d)); } else { activityDistance.setText(""); } float t = 0; if (tmp.containsKey(DB.ACTIVITY.TIME)) { t = tmp.getAsFloat(DB.ACTIVITY.TIME); activityTime.setText(formatter.formatElapsedTime(Formatter.TXT_SHORT, (long) t)); } else { activityTime.setText(""); } if (d != 0 && t != 0) { activityPace.setText(formatter.formatPace(Formatter.TXT_LONG, t / d)); } else { activityPace.setText(""); } if (tmp.containsKey(DB.ACTIVITY.COMMENT)) { notes.setText(tmp.getAsString(DB.ACTIVITY.COMMENT)); } if (tmp.containsKey(DB.ACTIVITY.SPORT)) { sport.setValue(tmp.getAsInteger(DB.ACTIVITY.SPORT)); } }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
private void showMessagesNotification(AccountPreferences pref, StringLongPair[] pairs, ContentValues[] valuesArray) {/* w ww. j av a 2 s . co m*/ final long accountId = pref.getAccountId(); final long prevOldestId = mReadStateManager.getPosition(TAG_OLDEST_MESSAGES, String.valueOf(accountId)); long oldestId = -1; for (final ContentValues contentValues : valuesArray) { final long messageId = contentValues.getAsLong(DirectMessages.MESSAGE_ID); oldestId = oldestId < 0 ? messageId : Math.min(oldestId, messageId); if (messageId <= prevOldestId) return; } mReadStateManager.setPosition(TAG_OLDEST_MESSAGES, String.valueOf(accountId), oldestId, false); final Context context = getContext(); final Resources resources = context.getResources(); final NotificationManager nm = getNotificationManager(); final ArrayList<Expression> orExpressions = new ArrayList<>(); final String prefix = accountId + "-"; final int prefixLength = prefix.length(); final Set<Long> senderIds = new CompactHashSet<>(); for (StringLongPair pair : pairs) { final String key = pair.getKey(); if (key.startsWith(prefix)) { final long senderId = Long.parseLong(key.substring(prefixLength)); senderIds.add(senderId); final Expression expression = Expression.and(Expression.equals(DirectMessages.SENDER_ID, senderId), Expression.greaterThan(DirectMessages.MESSAGE_ID, pair.getValue())); orExpressions.add(expression); } } orExpressions .add(Expression.notIn(new Column(DirectMessages.SENDER_ID), new RawItemArray(senderIds.toArray()))); final Expression selection = Expression.and(Expression.equals(DirectMessages.ACCOUNT_ID, accountId), Expression.greaterThan(DirectMessages.MESSAGE_ID, prevOldestId), Expression.or(orExpressions.toArray(new Expression[orExpressions.size()]))); final String filteredSelection = selection.getSQL(); final String[] userProjection = { DirectMessages.SENDER_ID, DirectMessages.SENDER_NAME, DirectMessages.SENDER_SCREEN_NAME }; final String[] messageProjection = { DirectMessages.MESSAGE_ID, DirectMessages.SENDER_ID, DirectMessages.SENDER_NAME, DirectMessages.SENDER_SCREEN_NAME, DirectMessages.TEXT_UNESCAPED, DirectMessages.MESSAGE_TIMESTAMP }; final Cursor messageCursor = mDatabaseWrapper.query(DirectMessages.Inbox.TABLE_NAME, messageProjection, filteredSelection, null, null, null, DirectMessages.DEFAULT_SORT_ORDER); final Cursor userCursor = mDatabaseWrapper.query(DirectMessages.Inbox.TABLE_NAME, userProjection, filteredSelection, null, DirectMessages.SENDER_ID, null, DirectMessages.DEFAULT_SORT_ORDER); try { final int usersCount = userCursor.getCount(); final int messagesCount = messageCursor.getCount(); if (messagesCount == 0 || usersCount == 0) return; final String accountName = Utils.getAccountName(context, accountId); final String accountScreenName = Utils.getAccountScreenName(context, accountId); final int idxMessageText = messageCursor.getColumnIndex(DirectMessages.TEXT_UNESCAPED), idxMessageTimestamp = messageCursor.getColumnIndex(DirectMessages.MESSAGE_TIMESTAMP), idxMessageId = messageCursor.getColumnIndex(DirectMessages.MESSAGE_ID), idxMessageUserId = messageCursor.getColumnIndex(DirectMessages.SENDER_ID), idxMessageUserName = messageCursor.getColumnIndex(DirectMessages.SENDER_NAME), idxMessageUserScreenName = messageCursor.getColumnIndex(DirectMessages.SENDER_SCREEN_NAME), idxUserName = userCursor.getColumnIndex(DirectMessages.SENDER_NAME), idxUserScreenName = userCursor.getColumnIndex(DirectMessages.SENDER_NAME), idxUserId = userCursor.getColumnIndex(DirectMessages.SENDER_NAME); final CharSequence notificationTitle = resources.getQuantityString(R.plurals.N_new_messages, messagesCount, messagesCount); final String notificationContent; userCursor.moveToFirst(); final String displayName = UserColorNameUtils.getUserNickname(context, userCursor.getLong(idxUserId), mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName)); if (usersCount == 1) { if (messagesCount == 1) { notificationContent = context.getString(R.string.notification_direct_message, displayName); } else { notificationContent = context.getString(R.string.notification_direct_message_multiple_messages, displayName, messagesCount); } } else { notificationContent = context.getString(R.string.notification_direct_message_multiple_users, displayName, usersCount - 1, messagesCount); } final LongSparseArray<Long> idsMap = new LongSparseArray<>(); // Add rich notification and get latest tweet timestamp long when = -1; final InboxStyle style = new InboxStyle(); for (int i = 0; messageCursor.moveToPosition(i) && i < messagesCount; i++) { if (when < 0) { when = messageCursor.getLong(idxMessageTimestamp); } if (i < 5) { final SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(UserColorNameUtils.getUserNickname(context, messageCursor.getLong(idxUserId), mNameFirst ? messageCursor.getString(idxMessageUserName) : messageCursor.getString(idxMessageUserScreenName))); sb.setSpan(new StyleSpan(Typeface.BOLD), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sb.append(' '); sb.append(messageCursor.getString(idxMessageText)); style.addLine(sb); } final long userId = messageCursor.getLong(idxMessageUserId); final long messageId = messageCursor.getLong(idxMessageId); idsMap.put(userId, Math.max(idsMap.get(userId, -1L), messageId)); } if (mNameFirst) { style.setSummaryText(accountName); } else { style.setSummaryText("@" + accountScreenName); } final StringLongPair[] positions = new StringLongPair[idsMap.size()]; for (int i = 0, j = idsMap.size(); i < j; i++) { positions[i] = new StringLongPair(String.valueOf(idsMap.keyAt(i)), idsMap.valueAt(i)); } // Setup notification final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setAutoCancel(true); builder.setSmallIcon(R.drawable.ic_stat_direct_message); builder.setTicker(notificationTitle); builder.setContentTitle(notificationTitle); builder.setContentText(notificationContent); builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); builder.setContentIntent(getContentIntent(context, AUTHORITY_DIRECT_MESSAGES, accountId)); builder.setContentIntent(getDeleteIntent(context, AUTHORITY_DIRECT_MESSAGES, accountId, positions)); builder.setNumber(messagesCount); builder.setWhen(when); builder.setStyle(style); builder.setColor(pref.getNotificationLightColor()); setNotificationPreferences(builder, pref, pref.getDirectMessagesNotificationType()); nm.notify("messages_" + accountId, NOTIFICATION_ID_DIRECT_MESSAGES, builder.build()); Utils.sendPebbleNotification(context, notificationContent); } finally { messageCursor.close(); userCursor.close(); } }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
@Override public int bulkInsert(final Uri uri, @NonNull final ContentValues[] valuesArray) { try {// www . j a v a 2 s . c o m final int tableId = getTableId(uri); final String table = getTableNameById(tableId); checkWritePermission(tableId, table); switch (tableId) { case TABLE_ID_DIRECT_MESSAGES_CONVERSATION: case TABLE_ID_DIRECT_MESSAGES: case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRIES: return 0; } int result = 0; final long[] newIds = new long[valuesArray.length]; if (table != null) { mDatabaseWrapper.beginTransaction(); if (tableId == TABLE_ID_CACHED_USERS) { for (final ContentValues values : valuesArray) { final Expression where = Expression.equals(CachedUsers.USER_ID, values.getAsLong(CachedUsers.USER_ID)); mDatabaseWrapper.update(table, values, where.getSQL(), null); newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE); } } else if (tableId == TABLE_ID_SEARCH_HISTORY) { for (final ContentValues values : valuesArray) { values.put(SearchHistory.RECENT_QUERY, System.currentTimeMillis()); final Expression where = Expression.equalsArgs(SearchHistory.QUERY); final String[] args = { values.getAsString(SearchHistory.QUERY) }; mDatabaseWrapper.update(table, values, where.getSQL(), args); newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE); } } else if (shouldReplaceOnConflict(tableId)) { for (final ContentValues values : valuesArray) { newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE); } } else { for (final ContentValues values : valuesArray) { newIds[result++] = mDatabaseWrapper.insert(table, null, values); } } mDatabaseWrapper.setTransactionSuccessful(); mDatabaseWrapper.endTransaction(); } if (result > 0) { onDatabaseUpdated(tableId, uri); } onNewItemsInserted(uri, tableId, valuesArray, newIds); return result; } catch (final SQLException e) { Crashlytics.logException(e); throw new IllegalStateException(e); } }
From source file:com.ichi2.anki.provider.CardContentProvider.java
@Override public Uri insert(Uri uri, ContentValues values) { Timber.d("CardContentProvider.insert"); Collection col = CollectionHelper.getInstance().getCol(getContext()); if (col == null) { return null; }/* w w w. ja v a 2 s.com*/ // Find out what data the user is requesting int match = sUriMatcher.match(uri); switch (match) { case NOTES: { /* Insert new note with specified fields and tags */ Long modelId = values.getAsLong(FlashCardsContract.Note.MID); String flds = values.getAsString(FlashCardsContract.Note.FLDS); String tags = values.getAsString(FlashCardsContract.Note.TAGS); // Create empty note com.ichi2.libanki.Note newNote = new com.ichi2.libanki.Note(col, col.getModels().get(modelId)); // Set fields String[] fldsArray = Utils.splitFields(flds); // Check that correct number of flds specified if (fldsArray.length != newNote.getFields().length) { throw new IllegalArgumentException("Incorrect flds argument : " + flds); } for (int idx = 0; idx < fldsArray.length; idx++) { newNote.setField(idx, fldsArray[idx]); } // Set tags if (tags != null) { newNote.setTagsFromStr(tags); } // Add to collection col.addNote(newNote); return Uri.withAppendedPath(FlashCardsContract.Note.CONTENT_URI, Long.toString(newNote.getId())); } case NOTES_ID: // Note ID is generated automatically by libanki throw new IllegalArgumentException("Not possible to insert note with specific ID"); case NOTES_ID_CARDS: // Cards are generated automatically by libanki throw new IllegalArgumentException("Not possible to insert cards directly (only through NOTES)"); case NOTES_ID_CARDS_ORD: // Cards are generated automatically by libanki throw new IllegalArgumentException("Not possible to insert cards directly (only through NOTES)"); case MODELS: // Get input arguments String modelName = values.getAsString(FlashCardsContract.Model.NAME); String css = values.getAsString(FlashCardsContract.Model.CSS); Long did = values.getAsLong(FlashCardsContract.Model.DECK_ID); String fieldNames = values.getAsString(FlashCardsContract.Model.FIELD_NAMES); Integer numCards = values.getAsInteger(FlashCardsContract.Model.NUM_CARDS); // Throw exception if required fields empty if (modelName == null || fieldNames == null || numCards == null) { throw new IllegalArgumentException("Model name, field_names, and num_cards can't be empty"); } // Create a new model Models mm = col.getModels(); JSONObject newModel = mm.newModel(modelName); try { // Add the fields String[] allFields = Utils.splitFields(fieldNames); for (String f : allFields) { mm.addField(newModel, mm.newField(f)); } // Add some empty card templates for (int idx = 0; idx < numCards; idx++) { JSONObject t = mm.newTemplate("Card " + (idx + 1)); t.put("qfmt", String.format("{{%s}}", allFields[0])); String answerField = allFields[0]; if (allFields.length > 1) { answerField = allFields[1]; } t.put("afmt", String.format("{{FrontSide}}\\n\\n<hr id=answer>\\n\\n{{%s}}", answerField)); mm.addTemplate(newModel, t); } // Add the CSS if specified if (css != null) { newModel.put("css", css); } // Add the did if specified if (did != null) { newModel.put("did", did); } // Add the model to collection (from this point on edits will require a full-sync) mm.add(newModel); mm.save(newModel); // TODO: is this necessary? // Get the mid and return a URI String mid = Long.toString(newModel.getLong("id")); return Uri.withAppendedPath(FlashCardsContract.Model.CONTENT_URI, mid); } catch (ConfirmModSchemaException e) { // This exception should never be thrown when inserting new models Timber.e(e, "Unexpected ConfirmModSchema exception adding new model %s", modelName); throw new IllegalArgumentException("ConfirmModSchema exception adding new model " + modelName); } catch (JSONException e) { Timber.e(e, "Could not set a field of new model %s", modelName); return null; } case MODELS_ID: // Model ID is generated automatically by libanki throw new IllegalArgumentException("Not possible to insert model with specific ID"); case MODELS_ID_TEMPLATES: // Adding new templates after the model is created could require a full-sync throw new IllegalArgumentException("Templates can only be added at the time of model insertion"); case MODELS_ID_TEMPLATES_ID: // Adding new templates after the model is created could require a full-sync throw new IllegalArgumentException("Templates can only be added at the time of model insertion"); case SCHEDULE: // Doesn't make sense to insert an object into the schedule table throw new IllegalArgumentException("Not possible to perform insert operation on schedule"); case DECKS: // Insert new deck with specified name String deckName = values.getAsString(FlashCardsContract.Deck.DECK_NAME); did = col.getDecks().id(deckName); return Uri.withAppendedPath(FlashCardsContract.Deck.CONTENT_ALL_URI, Long.toString(did)); case DECK_SELECTED: // Can't have more than one selected deck throw new IllegalArgumentException("Selected deck can only be queried and updated"); case DECKS_ID: // Deck ID is generated automatically by libanki throw new IllegalArgumentException("Not possible to insert deck with specific ID"); default: // Unknown URI type throw new IllegalArgumentException("uri " + uri + " is not supported"); } }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * Parse a content retrieved from storage. * @param values content as returned by the storage. * @return content./* w w w .ja va 2 s . c o m*/ * @throws Exception parsing problem, most likely invalid XML. */ private EngagementReachContent parseContentFromStorage(ContentValues values) throws Exception { /* Parse payload */ com.microsoft.azure.engagement.reach.CampaignId campaignId = new CampaignId( values.getAsString(CAMPAIGN_ID)); EngagementReachContent content = parseContent(campaignId, values); /* Parse state */ content.setState(values); /* Parse local id */ content.setLocalId(values.getAsLong(OID)); return content; }
From source file:com.csipsimple.service.SipNotifications.java
public void showNotificationForMissedCall(ContentValues callLog) { int icon = android.R.drawable.stat_notify_missed_call; CharSequence tickerText = context.getText(R.string.missed_call); long when = System.currentTimeMillis(); if (missedCallNotification == null) { missedCallNotification = new NotificationCompat.Builder(context); missedCallNotification.setSmallIcon(icon); missedCallNotification.setTicker(tickerText); missedCallNotification.setWhen(when); missedCallNotification.setOnlyAlertOnce(true); missedCallNotification.setAutoCancel(true); missedCallNotification.setDefaults(Notification.DEFAULT_ALL); }//from www .j a v a 2s . c om Intent notificationIntent = new Intent(SipManager.ACTION_SIP_CALLLOG); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); String remoteContact = callLog.getAsString(CallLog.Calls.NUMBER); long accId = callLog.getAsLong(SipManager.CALLLOG_PROFILE_ID_FIELD); missedCallNotification.setContentTitle(formatNotificationTitle(R.string.missed_call, accId)); missedCallNotification.setContentText(formatRemoteContactString(remoteContact)); missedCallNotification.setContentIntent(contentIntent); notificationManager.notify(CALLLOG_NOTIF_ID, missedCallNotification.build()); }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Scan reach database and notify the first content that match the current U.I context * @param replaySystemNotifications true iff system notifications must be replayed. *///from w w w. j ava 2s. c o m private void scanContent(boolean replaySystemNotifications) { /* Change state */ mScanning = true; /* For all database rows */ Scanner scanner = mDB.getScanner(); for (ContentValues values : scanner) { /* Parsing may fail */ CapptainReachContent content = null; try { /* Parse content */ content = parseContent(values); /* Possibly generate a notification */ notifyContent(content, replaySystemNotifications); } catch (Exception e) { /* * If the content was parsed but an error occurred while notifying, send "dropped" feedback * and delete */ if (content != null) content.dropContent(mContext); /* Otherwise we just delete */ else deleteContent(values.getAsLong(ID), values.getAsLong(DOWNLOAD_ID)); /* In any case we continue parsing */ } } /* Close scanner */ scanner.close(); /* Scan finished */ mScanning = false; }