public void testLookupUri() throws Exception { TestRawContact rawContact = mBuilder.newRawContact().insert().load(); TestContact contact = rawContact.getContact().load(); Uri contactUri = contact.getUri(); long contactId = contact.getId(); String lookupKey = contact.getString(Contacts.LOOKUP_KEY); Uri lookupUri = Contacts.getLookupUri(contactId, lookupKey); assertEquals( ContentUris.withAppendedId( Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), contactId), lookupUri); Uri nullLookupUri = Contacts.getLookupUri(contactId, null); assertNull(nullLookupUri); Uri emptyLookupUri = Contacts.getLookupUri(contactId, ""); assertNull(emptyLookupUri); Uri lookupUri2 = Contacts.getLookupUri(mResolver, contactUri); assertEquals(lookupUri, lookupUri2); Uri contactUri2 = Contacts.lookupContact(mResolver, lookupUri); assertEquals(contactUri, contactUri2); }
public void testMarkAsContacted() throws Exception { TestRawContact rawContact = mBuilder.newRawContact().insert().load(); TestContact contact = rawContact.getContact().load(); long oldLastContacted = contact.getLong(Contacts.LAST_TIME_CONTACTED); Contacts.markAsContacted(mResolver, contact.getId()); contact.load(); // Reload long lastContacted = contact.getLong(Contacts.LAST_TIME_CONTACTED); assertTrue(oldLastContacted < lastContacted); oldLastContacted = lastContacted; Contacts.markAsContacted(mResolver, contact.getId()); contact.load(); lastContacted = contact.getLong(Contacts.LAST_TIME_CONTACTED); assertTrue(oldLastContacted < lastContacted); }
@Override protected void tearDown() throws Exception { super.tearDown(); mBuilder.cleanup(); }
public void testProjection() throws Exception { final TestRawContact rawContact = mBuilder.newRawContact().insert().load(); rawContact .newDataRow(StructuredName.CONTENT_ITEM_TYPE) .with(StructuredName.GIVEN_NAME, "xxx") .insert(); final TestContact contact = rawContact.getContact().load(); final long contactId = contact.getId(); final String lookupKey = contact.getString(Contacts.LOOKUP_KEY); final String[] PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.DISPLAY_NAME_PRIMARY, Contacts.DISPLAY_NAME_ALTERNATIVE, Contacts.DISPLAY_NAME_SOURCE, Contacts.PHONETIC_NAME, Contacts.PHONETIC_NAME_STYLE, Contacts.SORT_KEY_PRIMARY, Contacts.SORT_KEY_ALTERNATIVE, Contacts.LAST_TIME_CONTACTED, Contacts.TIMES_CONTACTED, Contacts.STARRED, Contacts.PINNED, Contacts.IN_DEFAULT_DIRECTORY, Contacts.IN_VISIBLE_GROUP, Contacts.PHOTO_ID, Contacts.PHOTO_FILE_ID, Contacts.PHOTO_URI, Contacts.PHOTO_THUMBNAIL_URI, Contacts.CUSTOM_RINGTONE, Contacts.HAS_PHONE_NUMBER, Contacts.SEND_TO_VOICEMAIL, Contacts.IS_USER_PROFILE, Contacts.LOOKUP_KEY, Contacts.NAME_RAW_CONTACT_ID, Contacts.CONTACT_PRESENCE, Contacts.CONTACT_CHAT_CAPABILITY, Contacts.CONTACT_STATUS, Contacts.CONTACT_STATUS_TIMESTAMP, Contacts.CONTACT_STATUS_RES_PACKAGE, Contacts.CONTACT_STATUS_LABEL, Contacts.CONTACT_STATUS_ICON, Contacts.CONTACT_LAST_UPDATED_TIMESTAMP }; // Contacts.CONTENT_URI DatabaseAsserts.checkProjection( mResolver, Contacts.CONTENT_URI, PROJECTION, new long[] {contact.getId()}); // Contacts.CONTENT_FILTER_URI DatabaseAsserts.checkProjection( mResolver, Contacts.CONTENT_FILTER_URI.buildUpon().appendEncodedPath("xxx").build(), PROJECTION, new long[] {contact.getId()}); // Contacts.CONTENT_LOOKUP_URI DatabaseAsserts.checkProjection( mResolver, Contacts.getLookupUri(contactId, lookupKey), PROJECTION, new long[] {contact.getId()}); }