List of usage examples for android.content ContentUris parseId
public static long parseId(Uri contentUri)
From source file:com.csipsimple.db.DBProvider.java
@Override public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count;/*from w ww . j av a 2 s .c o m*/ String finalWhere; int matched = URI_MATCHER.match(uri); List<String> possibles = getPossibleFieldsForType(matched); checkSelection(possibles, where); switch (matched) { case ACCOUNTS: count = db.update(SipProfile.ACCOUNTS_TABLE_NAME, values, where, whereArgs); break; case ACCOUNTS_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipProfile.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipProfile.ACCOUNTS_TABLE_NAME, values, finalWhere, whereArgs); break; case CALLLOGS: count = db.update(SipManager.CALLLOGS_TABLE_NAME, values, where, whereArgs); break; case CALLLOGS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(CallLog.Calls._ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipManager.CALLLOGS_TABLE_NAME, values, finalWhere, whereArgs); break; case FILTERS: count = db.update(SipManager.FILTERS_TABLE_NAME, values, where, whereArgs); break; case FILTERS_ID: finalWhere = DatabaseUtilsCompat.concatenateWhere(Filter._ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipManager.FILTERS_TABLE_NAME, values, finalWhere, whereArgs); break; case MESSAGES: count = db.update(SipMessage.MESSAGES_TABLE_NAME, values, where, whereArgs); break; case MESSAGES_ID: finalWhere = DatabaseUtilsCompat .concatenateWhere(SipMessage.FIELD_ID + " = " + ContentUris.parseId(uri), where); count = db.update(SipMessage.MESSAGES_TABLE_NAME, values, where, whereArgs); break; case ACCOUNTS_STATUS_ID: long id = ContentUris.parseId(uri); synchronized (profilesStatus) { SipProfileState ps = new SipProfileState(); if (profilesStatus.containsKey(id)) { ContentValues currentValues = profilesStatus.get(id); ps.createFromContentValue(currentValues); } ps.createFromContentValue(values); ContentValues cv = ps.getAsContentValue(); cv.put(SipProfileState.ACCOUNT_ID, id); profilesStatus.put(id, cv); Log.d(THIS_FILE, "Updated " + cv); } count = 1; break; default: throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } getContext().getContentResolver().notifyChange(uri, null); long rowId = -1; if (matched == ACCOUNTS_ID || matched == ACCOUNTS_STATUS_ID) { rowId = ContentUris.parseId(uri); } if (rowId >= 0) { if (matched == ACCOUNTS_ID) { // Don't broadcast if we only changed wizard or only changed priority boolean doBroadcast = true; if (values.size() == 1) { if (values.containsKey(SipProfile.FIELD_WIZARD)) { doBroadcast = false; } else if (values.containsKey(SipProfile.FIELD_PRIORITY)) { doBroadcast = false; } } if (doBroadcast) { broadcastAccountChange(rowId); } } else if (matched == ACCOUNTS_STATUS_ID) { broadcastRegistrationChange(rowId); } } if (matched == FILTERS || matched == FILTERS_ID) { Filter.resetCache(); } return count; }
From source file:cz.maresmar.sfm.view.portal.PortalDetailFragment.java
/** * Saves data from UI a do portal test in plugin * * @return {@link Uri} of saved portal/*from w ww. ja va2 s . co m*/ */ public Uri saveAndTestData() { // Gets data from portal fragment Uri portalUri = saveData(); long portalId = ContentUris.parseId(portalUri); // Test the new data String plugin = getSelectedPluginId(); PortalTestHandler.requestTest(getContext(), plugin, portalId); return portalUri; }
From source file:com.rukman.emde.smsgroups.syncadapter.SyncAdapter.java
private long updateSyncRecord(ContentProviderClient provider) throws RemoteException, OperationApplicationException { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ContentProviderOperation op = ContentProviderOperation.newInsert(GMSSyncs.CONTENT_URI) .withValue(GMSSync.SYNC_DATE, System.currentTimeMillis()).build(); ops.add(op);/* w w w.ja va2 s . co m*/ ContentProviderResult[] results = provider.applyBatch(ops); return (results[0].uri != null) ? ContentUris.parseId(results[0].uri) : -1L; }
From source file:org.kontalk.ui.ComposeMessageFragment.java
/** Sends out a binary message. */ @Override//from ww w .j a v a2s . c om public void sendBinaryMessage(Uri uri, String mime, boolean media, Class<? extends MessageComponent<?>> klass) { Log.v(TAG, "sending binary content: " + uri); Uri newMsg = null; String msgId = null; File previewFile = null; long length = -1; boolean encrypted = Preferences.getEncryptionEnabled(getActivity()); int compress = 0; if (klass == ImageComponent.class) { compress = Preferences.getImageCompression(getActivity()); } try { // TODO convert to thread (?) offlineModeWarning(); msgId = MessageCenterService.messageId(); // generate thumbnail // FIXME this is blocking!!!! if (media && klass == ImageComponent.class) { // FIXME hard-coded to ImageComponent String filename = ImageComponent.buildMediaFilename(msgId, MediaStorage.THUMBNAIL_MIME_NETWORK); previewFile = MediaStorage.cacheThumbnail(getActivity(), uri, filename, true); } length = MediaStorage.getLength(getActivity(), uri); // save to database ContentValues values = new ContentValues(); values.put(Messages.MESSAGE_ID, msgId); values.put(Messages.PEER, mUserJID); /* TODO ask for a text to send with the image values.put(Messages.BODY_MIME, TextComponent.MIME_TYPE); values.put(Messages.BODY_CONTENT, content.getBytes()); values.put(Messages.BODY_LENGTH, content.length()); */ values.put(Messages.UNREAD, false); // of course outgoing messages are not encrypted in database values.put(Messages.ENCRYPTED, false); values.put(Messages.SECURITY_FLAGS, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT); values.put(Messages.DIRECTION, Messages.DIRECTION_OUT); values.put(Messages.TIMESTAMP, System.currentTimeMillis()); values.put(Messages.STATUS, Messages.STATUS_SENDING); if (previewFile != null) values.put(Messages.ATTACHMENT_PREVIEW_PATH, previewFile.getAbsolutePath()); values.put(Messages.ATTACHMENT_MIME, mime); values.put(Messages.ATTACHMENT_LOCAL_URI, uri.toString()); values.put(Messages.ATTACHMENT_LENGTH, length); values.put(Messages.ATTACHMENT_COMPRESS, compress); newMsg = getActivity().getContentResolver().insert(Messages.CONTENT_URI, values); } catch (Exception e) { Log.e(TAG, "unable to store media", e); } if (newMsg != null) { // update thread id from the inserted message if (threadId <= 0) { Cursor c = getActivity().getContentResolver().query(newMsg, new String[] { Messages.THREAD_ID }, null, null, null); if (c.moveToFirst()) { threadId = c.getLong(0); startQuery(false); } else { Log.v(TAG, "no data - cannot start query for this composer"); } c.close(); } // send message! String previewPath = (previewFile != null) ? previewFile.getAbsolutePath() : null; MessageCenterService.sendBinaryMessage(getActivity(), mUserJID, mime, uri, length, previewPath, encrypted, compress, ContentUris.parseId(newMsg), msgId); } else { getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), R.string.err_store_message_failed, Toast.LENGTH_LONG).show(); } }); } }
From source file:com.android.contacts.ContactSaveService.java
/** * Find the ID of a newly-inserted raw-contact. If none exists, return -1. *///from ww w .j a v a2s . co m private long getInsertedRawContactId(final ArrayList<CPOWrapper> diffWrapper, final ContentProviderResult[] results) { if (results == null) { return -1; } final int diffSize = diffWrapper.size(); final int numResults = results.length; for (int i = 0; i < diffSize && i < numResults; i++) { final CPOWrapper cpoWrapper = diffWrapper.get(i); final boolean isInsert = CompatUtils.isInsertCompat(cpoWrapper); if (isInsert && cpoWrapper.getOperation().getUri().getEncodedPath() .contains(RawContacts.CONTENT_URI.getEncodedPath())) { return ContentUris.parseId(results[i].uri); } } return -1; }
From source file:org.gege.caldavsyncadapter.caldav.entities.CalendarEvent.java
/** * creates a new androidEvent from a given calendarEvent * @param androidCalendar// ww w .j a v a 2s . com * @return * @throws ClientProtocolException * @throws IOException * @throws CaldavProtocolException * @throws RemoteException * @throws ParserException * @see {@link SyncAdapter#synchroniseEvents(CaldavFacade, Account, ContentProviderClient, Uri, DavCalendar, SyncStats)} */ public boolean createAndroidEvent(DavCalendar androidCalendar) throws ClientProtocolException, IOException, CaldavProtocolException, RemoteException, ParserException { boolean Result = false; boolean BodyFetched = this.fetchBody(); int CountAttendees = 0; int CountReminders = 0; if (BodyFetched) { //calendarEvent.readContentValues(calendarUri); this.readContentValues(); this.setAndroidCalendarId(ContentUris.parseId(androidCalendar.getAndroidCalendarUri())); Uri uri = this.mProvider.insert( asSyncAdapter(Events.CONTENT_URI, this.mAccount.name, this.mAccount.type), this.ContentValues); this.setAndroidEventUri(uri); Log.d(TAG, "Creating calendar event for " + uri.toString()); //check the attendees java.util.ArrayList<ContentValues> AttendeeList = this.getAttandees(); for (ContentValues Attendee : AttendeeList) { this.mProvider.insert(Attendees.CONTENT_URI, Attendee); CountAttendees += 1; } //check the reminders java.util.ArrayList<ContentValues> ReminderList = this.getReminders(); for (ContentValues Reminder : ReminderList) { this.mProvider.insert(Reminders.CONTENT_URI, Reminder); CountReminders += 1; } if ((CountAttendees > 0) || (CountReminders > 0)) { //the events gets dirty when attendees or reminders were added AndroidEvent androidEvent = this.getAndroidEvent(androidCalendar); androidEvent.ContentValues.put(Events.DIRTY, 0); int RowCount = this.mProvider.update( asSyncAdapter(androidEvent.getUri(), this.mAccount.name, this.mAccount.type), androidEvent.ContentValues, null, null); Result = (RowCount == 1); } else { Result = true; } } return Result; }
From source file:com.android.contacts.ContactSaveService.java
private void createGroup(Intent intent) { String accountType = intent.getStringExtra(EXTRA_ACCOUNT_TYPE); String accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME); String dataSet = intent.getStringExtra(EXTRA_DATA_SET); String label = intent.getStringExtra(EXTRA_GROUP_LABEL); final long[] rawContactsToAdd = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_ADD); // Create the new group final Uri groupUri = mGroupsDao.create(label, new AccountWithDataSet(accountName, accountType, dataSet)); final ContentResolver resolver = getContentResolver(); // If there's no URI, then the insertion failed. Abort early because group members can't be // added if the group doesn't exist if (groupUri == null) { Log.e(TAG, "Couldn't create group with label " + label); return;/*from w w w.j a v a2 s .c om*/ } // Add new group members addMembersToGroup(resolver, rawContactsToAdd, ContentUris.parseId(groupUri)); ContentValues values = new ContentValues(); // TODO: Move this into the contact editor where it belongs. This needs to be integrated // with the way other intent extras that are passed to the // {@link ContactEditorActivity}. values.clear(); values.put(Data.MIMETYPE, GroupMembership.CONTENT_ITEM_TYPE); values.put(GroupMembership.GROUP_ROW_ID, ContentUris.parseId(groupUri)); Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT); callbackIntent.setData(groupUri); // TODO: This can be taken out when the above TODO is addressed callbackIntent.putExtra(ContactsContract.Intents.Insert.DATA, Lists.newArrayList(values)); deliverCallback(callbackIntent); }
From source file:org.exoplatform.utils.ExoDocumentUtils.java
/** * Returns a DocumentInfo with info coming from the file at the given URI * /*w ww . j av a 2 s . co m*/ * @param document the URI of a file or a content * @param context * @return a DocumentInfo or null if an error occurs */ public static DocumentInfo documentInfoFromUri(Uri document, Context context) { if (document == null) return null; if (document.toString().startsWith("content://")) { /* * Some apps send fake content:// URI with real file:// URI inside * E.g. open ASTRO File Manager > View File > Share : * * content://authority/-1/1/file:///sdcard/path/file.jpg/ACTUAL/123 * * Then we extract the real URI and pass it to documentFromFileUri(...) */ String decodedUri = Uri.decode(document.toString()); int fileIdx = decodedUri.indexOf("file://"); if (fileIdx > -1) { long id = -1; try { id = ContentUris.parseId(document); } catch (NumberFormatException e) { Log.e(LOG_TAG, e.getMessage(), e); } catch (UnsupportedOperationException e) { Log.e(LOG_TAG, e.getMessage(), e); } String fileUri = decodedUri.substring(fileIdx); fileUri = fileUri.replaceAll("(/ACTUAL/)(" + id + ")", ""); return documentFromFileUri(Uri.parse(fileUri)); } else { return documentFromContentUri(document, context); } } else if (document.toString().startsWith("file://")) { return documentFromFileUri(document); } else { return null; // other formats not supported } }
From source file:org.gege.caldavsyncadapter.caldav.entities.CalendarEvent.java
/** * updates the attendees from a calendarEvent to its androidEvent. * the calendarEvent has to know its androidEvent via {@link CalendarEvent#setAndroidEventUri(Uri)} * @param provider// w w w .j a v a 2 s. co m * @return * @see SyncAdapter#updateAndroidEvent(ContentProviderClient, Account, AndroidEvent, CalendarEvent) */ private boolean updateAndroidAttendees() { boolean Result = false; try { String mSelectionClause = "(" + Attendees.EVENT_ID + " = ?)"; String[] mSelectionArgs = { Long.toString(ContentUris.parseId(this.getAndroidEventUri())) }; int RowDelete; RowDelete = this.mProvider.delete(Attendees.CONTENT_URI, mSelectionClause, mSelectionArgs); Log.d(TAG, "Attendees Deleted:" + String.valueOf(RowDelete)); java.util.ArrayList<ContentValues> AttendeeList = this.getAttandees(); for (ContentValues Attendee : AttendeeList) { this.mProvider.insert(Attendees.CONTENT_URI, Attendee); } Log.d(TAG, "Attendees Inserted:" + String.valueOf(AttendeeList.size())); Result = true; } catch (RemoteException e) { e.printStackTrace(); } return Result; }
From source file:org.gege.caldavsyncadapter.caldav.entities.CalendarEvent.java
/** * update the reminders from a calendarEvent to its androidEvent. * the calendarEvent has to know its androidEvent via {@link CalendarEvent#setAndroidEventUri(Uri)} * @param provider//w w w.j ava 2s. c o m * @return * @see SyncAdapter#updateAndroidEvent(ContentProviderClient, Account, AndroidEvent, CalendarEvent) */ private boolean updateAndroidReminder() { boolean Result = false; try { String mSelectionClause = "(" + Reminders.EVENT_ID + " = ?)"; String[] mSelectionArgs = { Long.toString(ContentUris.parseId(this.getAndroidEventUri())) }; int RowDelete; RowDelete = this.mProvider.delete(Reminders.CONTENT_URI, mSelectionClause, mSelectionArgs); Log.d(TAG, "Reminders Deleted:" + String.valueOf(RowDelete)); Uri ReminderUri; java.util.ArrayList<ContentValues> ReminderList = this.getReminders(); for (ContentValues Reminder : ReminderList) { ReminderUri = this.mProvider.insert(Reminders.CONTENT_URI, Reminder); System.out.println(ReminderUri); } Log.d(TAG, "Reminders Inserted:" + String.valueOf(ReminderList.size())); Result = true; } catch (RemoteException e) { e.printStackTrace(); } return Result; }