android.provider.ContactsContract.Data Java Examples

The following examples show how to use android.provider.ContactsContract.Data. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisplayActivity.java    From coursera-android with MIT License 6 votes vote down vote up
private void addRecordToBatchInsertOperation(String name,
                                             List<ContentProviderOperation> ops) {

    int position = ops.size();

    // First part of operation
    ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
            .withValue(RawContacts.ACCOUNT_TYPE, mType)
            .withValue(RawContacts.ACCOUNT_NAME, mName)
            .withValue(Contacts.STARRED, 1).build());

    // Second part of operation
    ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
            .withValueBackReference(Data.RAW_CONTACT_ID, position)
            .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
            .withValue(StructuredName.DISPLAY_NAME, name).build());

}
 
Example #2
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * Synchronously insert a contact with the designated @name into
 * the ContactsContentProvider.  This code is explained at
 * http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html.
 */
private void addContact(String name,
                        List<ContentProviderOperation> cpops) {
    final int position = cpops.size();

    // First part of operation.
    cpops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
              .withValue(RawContacts.ACCOUNT_TYPE,
                         mOps.getAccountType())
              .withValue(RawContacts.ACCOUNT_NAME,
                         mOps.getAccountName())
              .withValue(Contacts.STARRED,
                         1)
              .build());

    // Second part of operation.
    cpops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
              .withValueBackReference(Data.RAW_CONTACT_ID,
                                      position)
              .withValue(Data.MIMETYPE,
                         StructuredName.CONTENT_ITEM_TYPE)
              .withValue(StructuredName.DISPLAY_NAME,
                         name)
              .build());
}
 
Example #3
Source File: CallLog.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static void updateNormalizedNumber(Context context, ContentResolver resolver,
        String dataId, String number) {
    if (TextUtils.isEmpty(number) || TextUtils.isEmpty(dataId)) {
        return;
    }
    final String countryIso = getCurrentCountryIso(context);
    if (TextUtils.isEmpty(countryIso)) {
        return;
    }
    final String normalizedNumber = PhoneNumberUtils.formatNumberToE164(number,
            getCurrentCountryIso(context));
    if (TextUtils.isEmpty(normalizedNumber)) {
        return;
    }
    final ContentValues values = new ContentValues();
    values.put(Phone.NORMALIZED_NUMBER, normalizedNumber);
    resolver.update(Data.CONTENT_URI, values, Data._ID + "=?", new String[] {dataId});
}
 
Example #4
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * Synchronously insert a contact with the designated @name into
 * the ContactsContentProvider.  This code is explained at
 * http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html.
 */
private void addContact(String name,
                        List<ContentProviderOperation> cpops) {
    final int position = cpops.size();

    // First part of operation.
    cpops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
              .withValue(RawContacts.ACCOUNT_TYPE,
                         mOps.getAccountType())
              .withValue(RawContacts.ACCOUNT_NAME,
                         mOps.getAccountName())
              .withValue(Contacts.STARRED,
                         1)
              .build());

    // Second part of operation.
    cpops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
              .withValueBackReference(Data.RAW_CONTACT_ID,
                                      position)
              .withValue(Data.MIMETYPE,
                         StructuredName.CONTENT_ITEM_TYPE)
              .withValue(StructuredName.DISPLAY_NAME,
                         name)
              .build());
}
 
Example #5
Source File: ContactsManager.java    From tindroid with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the Lookup Key for a contact, or null if user isn't found.
 *
 * @param resolver a content resolver
 * @param uid      server-issued unique ID of the contact
 * @return the profile Data row id, or 0 if not found
 */
public static String getLookupKey(ContentResolver resolver, String uid) {
    final Cursor c = resolver.query(Data.CONTENT_URI, ProfileQuery.PROJECTION, ProfileQuery.SELECTION,
            new String[]{uid}, null);

    if (c == null) {
        return null;
    }

    String lookupKey = null;
    try {
        if (c.moveToFirst()) {
            lookupKey = c.getString(ProfileQuery.COLUMN_LOOKUP_KEY);
        }
    } finally {
        c.close();
    }

    return lookupKey;
}
 
Example #6
Source File: ContactsManager.java    From tindroid with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the Data id a contact's profile row, or 0 if the user isn't found.
 *
 * @param resolver a content resolver
 * @param uid      server-issued unique ID of the contact
 * @return the profile Data row id, or 0 if not found
 */
private static long lookupProfile(ContentResolver resolver, String uid) {
    final Cursor c = resolver.query(Data.CONTENT_URI, ProfileQuery.PROJECTION, ProfileQuery.SELECTION,
            new String[]{uid}, null);

    if (c == null) {
        return 0;
    }

    long profileId = 0;
    try {
        if (c.moveToFirst()) {
            profileId = c.getLong(ProfileQuery.COLUMN_ID);
        }
    } finally {
        c.close();
    }

    return profileId;
}
 
Example #7
Source File: AndroidContact.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
void updateNativeContactWithPresenceInfo(String value) {
    Log.d("[Contact] Adding presence information " + value);
    addChangesToCommit(
            ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                    .withValue(ContactsContract.Data.RAW_CONTACT_ID, mAndroidRawId)
                    .withValue(
                            ContactsContract.Data.MIMETYPE,
                            ContactsManager.getInstance()
                                    .getString(R.string.linphone_address_mime_type))
                    .withValue("data1", value) // phone number
                    .withValue(
                            "data2",
                            ContactsManager.getInstance()
                                    .getString(R.string.app_name)) // Summary
                    .withValue("data3", value) // Detail
                    .build());
}
 
Example #8
Source File: DisplayActivity.java    From coursera-android with MIT License 6 votes vote down vote up
private void addRecordToBatchInsertOperation(String name,
		List<ContentProviderOperation> ops) {

	int position = ops.size();

	// First part of operation
	ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
			.withValue(RawContacts.ACCOUNT_TYPE, mType)
			.withValue(RawContacts.ACCOUNT_NAME, mName)
			.withValue(Contacts.STARRED, 1).build());

	// Second part of operation
	ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
			.withValueBackReference(Data.RAW_CONTACT_ID, position)
			.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
			.withValue(StructuredName.DISPLAY_NAME, name).build());

}
 
Example #9
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
public static Photo getPhoto(ContentResolver c, long rawContactId){
	Photo photo = new Photo();
	String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId 
			+ "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";



	Cursor c1 = c.query(ContactsContract.Data.CONTENT_URI, new String[] {ContactsContract.CommonDataKinds.Photo.PHOTO, ContactsContract.Data.SYNC2, ContactsContract.Data.SYNC3 }, where , null, null);
	if (c1.getCount() > 0){
		c1.moveToLast();
		photo.data = c1.getBlob(c1.getColumnIndex(ContactsContract.CommonDataKinds.Photo.PHOTO));
		photo.timestamp = Long.valueOf(c1.getString(c1.getColumnIndex(ContactsContract.Data.SYNC2)));
		photo.url = c1.getString(c1.getColumnIndex(ContactsContract.Data.SYNC3));
	}
	c1.close();
	return photo;
}
 
Example #10
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
public static void addEmail(Context c, long rawContactId, String email){
	DeviceUtil.log(c, "adding email", email);
	String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId 
			+ "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE+ "'";
	Cursor cursor = c.getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { RawContacts.CONTACT_ID}, where, null, null);
	if (cursor.getCount() == 0){
		ContentValues contentValues = new ContentValues();
		//op.put(ContactsContract.CommonDataKinds.StructuredPostal.CONTACT_ID, );
		contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
		contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
		contentValues.put(ContactsContract.CommonDataKinds.Email.ADDRESS, email);
		c.getContentResolver().insert(ContactsContract.Data.CONTENT_URI, contentValues);
	}
	cursor.close();

}
 
Example #11
Source File: ContactsManager.java    From Linphone4Android with GNU General Public License v3.0 6 votes vote down vote up
public void deleteMultipleContactsAtOnce(List<String> ids) {
	String select = Data.CONTACT_ID + " = ?";
	ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

	for (String id : ids) {
		String[] args = new String[] { id };
		ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(select, args).build());
	}

	ContentResolver cr = ContactsManager.getInstance().getContentResolver();
	try {
		cr.applyBatch(ContactsContract.AUTHORITY, ops);
	} catch (Exception e) {
		Log.e(e);
	}
}
 
Example #12
Source File: ContactsUtils5.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Intent getAddContactIntent(String displayName, String csipUri) {
    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, Contacts.CONTENT_URI);
    intent.setType(Contacts.CONTENT_ITEM_TYPE);

    if (!TextUtils.isEmpty(displayName)) {
        intent.putExtra(Insert.NAME, displayName);
    }

    if (!TextUtils.isEmpty(csipUri)) {
        ArrayList<ContentValues> data = new ArrayList<ContentValues>();
        ContentValues csipProto = new ContentValues();
        csipProto.put(Data.MIMETYPE, CommonDataKinds.Im.CONTENT_ITEM_TYPE);
        csipProto.put(CommonDataKinds.Im.PROTOCOL, CommonDataKinds.Im.PROTOCOL_CUSTOM);
        csipProto.put(CommonDataKinds.Im.CUSTOM_PROTOCOL, SipManager.PROTOCOL_CSIP);
        csipProto.put(CommonDataKinds.Im.DATA, SipUri.getCanonicalSipContact(csipUri, false));
        data.add(csipProto);

        intent.putParcelableArrayListExtra(Insert.DATA, data);
    }

    return intent;
}
 
Example #13
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 6 votes vote down vote up
/**
 * Store all metadata info into a given contentvalues instance.
 * @param values A ContentValues instance.
 * @param metadata The Metadata instance to be saved to ContentValues.
 */
private void put(ContentValues values, Metadata metadata) {
    if (metadata.getID() > 0) {
        values.put(Data._ID, metadata.getID());
    }
    if (metadata.getRawContactID() > 0) {
        values.put(Data.RAW_CONTACT_ID, metadata.getRawContactID());
    }
    values.put(Data.MIMETYPE, metadata.getMimetype());
    for (int i = 0; i < SYNC_FIELDS.length; i++) {
        values.put(SYNC_FIELDS[i], metadata.getSync(i));
    }
    for (int i = 0; i < DATA_FIELDS.length; i++) {
        values.put(DATA_FIELDS[i], metadata.getData(i));
    }
    values.put(Data.DATA15, metadata.getBlob());
}
 
Example #14
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 6 votes vote down vote up
/**
 * Fetch the metadata of a single account. All results will be attached
 * to the contact.
 * @param contact The contact that should be enriched.
 */
private void fetchMetadata(RawContact contact) {
    try {
        Cursor cursor = provider.query(
                Data.CONTENT_URI,
                DATA_PROJECTION_MAP, 
                Data.RAW_CONTACT_ID + "=?",
                new String[]{Long.toString(contact.getID())},
                null);
        try {
            if (cursor.moveToFirst()) {
                do {
                    contact.setMetadata(newMetadata(cursor));
                } while (cursor.moveToNext());
            }
        } finally {
            cursor.close();
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
Example #15
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
public static void addBirthday(long rawContactId, String birthday){
	String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId 
			+ "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE
			+ "' AND " + ContactsContract.CommonDataKinds.Event.TYPE + " = '" + ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY + "'";
	Cursor cursor = ContactsSyncAdapterService.mContentResolver.query(ContactsContract.Data.CONTENT_URI, null, where, null, null);
	int count = cursor.getCount();
	cursor.close();
	if (count <= 0){
		ContentValues contentValues = new ContentValues();
		contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE);
		contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
		contentValues.put(ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY);
		contentValues.put(ContactsContract.CommonDataKinds.Event.START_DATE, birthday);
		
		try {
			ContactsSyncAdapterService.mContentResolver.insert(ContactsContract.Data.CONTENT_URI, contentValues);
		//	mContentResolver.applyBatch(ContactsContract.AUTHORITY,	operationList);
		} catch (Exception e) {
			e.printStackTrace();
			//Log.e("ERROR:" , e.^);
		}
	}
}
 
Example #16
Source File: FavoritesFragmentContainer2.java    From Contacts with MIT License 5 votes vote down vote up
@Override
protected String getAdditionalFilters()
{
	if (mPosition == 0)
	{
		return " AND " + Data.STARRED + " = " + 1;
	}
	else
	{
		Group group = (Group) mGroups.get(mPosition);
		return " AND " + CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = " + group.getId();
	}
}
 
Example #17
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called back by Android after the item has
 * been inserted into the Contacts Provider to perform the
 * completion task(s).
 */
@Override
public void onCompletion(int token,
                         Uri uri) {
    if (token == INSERT_RAW_CONTACT) {
        // If the token is INSERT_RAW_CONTACT then
        // make a ContentValues object containing
        // the data associated with RawContact.
        final ContentValues values =
            makeRawContactData
                (getArgs().getIterator().next(),
                 uri);

        // Initiate an asynchronous insert on the Contacts
        // Provider.
        getArgs().getAdapter()
                 .startInsert(this,
                              INSERT_RAW_CONTACT_DATA,
                              Data.CONTENT_URI,
                              values);
    } else if (token == INSERT_RAW_CONTACT_DATA) {
        // Increment the insertion count.
        getArgs().getCounter().increment();

        // Calls executeImpl() to trigger insertion of the next
        // contact (if any) in the Iterator.
        executeImpl();
    }
}
 
Example #18
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new status update based on the current cursor.
 * @param cursor The current DB cursor.
 * @return A new StatusUpdate instance.
 */
private StatusUpdate newStatusUpdate(Cursor cursor) {
    StatusUpdate statusUpdate = new StatusUpdate();

    int index = cursor.getColumnIndex(Data._ID);
    statusUpdate.setDataId(cursor.getLong(index));

    index = cursor.getColumnIndex(StatusUpdates.PRESENCE);
    statusUpdate.setPresence(Presence.byPresenceId(cursor.getInt(index)));

    index = cursor.getColumnIndex(StatusUpdates.STATUS);
    statusUpdate.setStatus(cursor.getString(index));

    return statusUpdate;
}
 
Example #19
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch a users status based on a account and user jid.
 * @param accountJid The account jid (aka your local jid).
 * @param jid The jid in question (aka the remote jid).
 * @return A new StatusUpdate instance, or null.
 */
public StatusUpdate getStatusUpdate(String accountJid, String jid) {
    // $%&# ok, so status updates will do magic
    // Solution? use the Data magic, and fill the missing blocks.
    // IM_HANDLER and IM_ACCOUNT is virtual anyway....
    try {
        Cursor cursor = provider.query(
                Data.CONTENT_URI,
                STATUS_UPDATES_IMPLICIT_PROJECTION_MAP,
                Data.MIMETYPE + "=? AND " +
                Data.SYNC2 + "=? AND " +
                Data.SYNC3 + "=?",
                new String[]{ImMetadata.MIMETYPE, accountJid, jid},
                null);
        if (!cursor.moveToFirst()) {
            cursor.close();
            StatusUpdate update = new StatusUpdate();
            update.setImAccount(accountJid);
            update.setImHandle(jid);
            return update;
        }

        StatusUpdate statusUpdate = newStatusUpdate(cursor);
        cursor.close();

        statusUpdate.setImAccount(accountJid);
        statusUpdate.setImHandle(jid);

        return statusUpdate;

    } catch (RemoteException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #20
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 5 votes vote down vote up
/**
 * Append all operations needed to store the current contact to a set of
 * operations.
 * @param contact The current contact with metadata.
 * @param operations A set of operations to be extended.
 */
public void persist(RawContact contact, ArrayList<ContentProviderOperation> operations) {
    int operationsStart = operations.size();
    Builder operation;
    if (contact.getID() == -1) {
        operation = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
    } else {
        operation = ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI);
        operation.withSelection(RawContacts._ID + "=?", new String[]{Long.toString(contact.getID())});
    }
    ContentValues values = new ContentValues();
    put(values, contact);
    operation.withValues(values);
    operations.add(operation.build());
    for (Metadata data: contact.getMetadata().values()) {
        values.clear();
        put(values, data);
        if (data instanceof DeletedMetadata) {
            operation = ContentProviderOperation.newDelete(Data.CONTENT_URI);
            operation.withValues(values);
            operation.withSelection(Data._ID + "=?", new String[]{Long.toString(contact.getID())});
            operations.add(operation.build());
            continue;
        }
        if (data.getID() == -1) {
            operation = ContentProviderOperation.newInsert(Data.CONTENT_URI);
        } else {
            operation = ContentProviderOperation.newUpdate(Data.CONTENT_URI);
            operation.withSelection(Data._ID + "=?", new String[]{Long.toString(data.getID())});
        }
        if (contact.getID() == -1) {
            operation.withValueBackReference(Data.RAW_CONTACT_ID, operationsStart);
            values.remove(Data.RAW_CONTACT_ID);
        } else {
            values.put(Data.RAW_CONTACT_ID, contact.getID());
        }
        operation.withValues(values);
        operations.add(operation.build());
    }
}
 
Example #21
Source File: AndroidContact.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
boolean isLinphoneAddressMimeEntryAlreadyExisting(String value) {
    boolean result = false;

    ContentResolver resolver =
            LinphoneContext.instance().getApplicationContext().getContentResolver();
    String[] projection = {"data1", "data3"};
    String selection =
            ContactsContract.Data.RAW_CONTACT_ID
                    + " = ? AND "
                    + Data.MIMETYPE
                    + " = ? AND data1 = ?";

    Cursor c =
            resolver.query(
                    ContactsContract.Data.CONTENT_URI,
                    projection,
                    selection,
                    new String[] {
                        mAndroidRawId,
                        ContactsManager.getInstance()
                                .getString(R.string.linphone_address_mime_type),
                        value
                    },
                    null);
    if (c != null) {
        if (c.moveToFirst()) {
            result = true;
        }
        c.close();
    }
    return result;
}
 
Example #22
Source File: FavoritesFragmentContainer2.java    From Contacts with MIT License 5 votes vote down vote up
@Override
protected Uri getUri()
{
	Uri uri = Data.CONTENT_URI;

	if (isFilterQuery())
	{
		uri = Uri.withAppendedPath(Data.CONTENT_URI, mSearchQuery);
	}

	return uri;
}
 
Example #23
Source File: FragmentContainer2.java    From Contacts with MIT License 5 votes vote down vote up
@Override
protected List<BaseType> doInBackground(Cursor... params)
{
	Set<String> set = new HashSet<String>();

	Cursor cursor = params[0];

	int idColumnIndex = cursor.getColumnIndex(Contacts.LOOKUP_KEY);

	if (cursor != null && !cursor.isClosed())
	{
		cursor.moveToFirst();
		while (!cursor.isAfterLast())
		{
			set.add("'" + cursor.getString(idColumnIndex) + "'");

			cursor.moveToNext();
		}
	}

	cursor.close();

	String selection = Data.LOOKUP_KEY + " IN (" + StringUtils.join(set, ",") + ")";
	long start = new Date().getTime();
	cursor = getActivity().getContentResolver().query(Data.CONTENT_URI, null, selection, null, SORT_BY);
	Log.d("FragmentContainer.LoaderTask2", "doInBackground: " + (new Date().getTime() - start));
	return super.doInBackground(cursor);
}
 
Example #24
Source File: FavoritesFragmentContainer.java    From Contacts with MIT License 5 votes vote down vote up
@Override
protected Uri getUri()
{
	if (mPosition > 0)
		return Data.CONTENT_URI;
	
	return super.getUri();
}
 
Example #25
Source File: FavoritesFragmentContainer.java    From Contacts with MIT License 5 votes vote down vote up
@Override
protected String getAdditionalFilters()
{
	if (mPosition == 0)
	{
		return " AND " + Contacts.STARRED + " = " + 1;
	}
	else
	{
		return " AND " + Data.MIMETYPE + " = ? AND " + CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = ?";
	}
}
 
Example #26
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
public static void updateContactLocation(long rawContactId, String location){
    if ((location == null || location.equals(""))){
        return;
    }
    String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId
            + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + StructuredPostal.CONTENT_ITEM_TYPE + "'";
    String[] projection = {StructuredPostal.FORMATTED_ADDRESS};

    Cursor cursor = ContactsSyncAdapterService.mContentResolver.query(ContactsContract.Data.CONTENT_URI, projection, where, null, null);
    boolean insert = false;
    if (cursor.getCount() == 0){
        insert = true;
    } else{
        cursor.moveToFirst();
        String oldloc = cursor.getString(cursor.getColumnIndex(StructuredPostal.FORMATTED_ADDRESS));
        if ((oldloc == null) || (!oldloc.equals(location))){
            ContactsSyncAdapterService.mContentResolver.delete(ContactsContract.Data.CONTENT_URI, where, null);
            insert = true;
        }
    }
    cursor.close();
    if (insert){
        ContentValues contentValues = new ContentValues();
        //op.put(ContactsContract.CommonDataKinds.StructuredPostal.CONTACT_ID, );
        contentValues.put(ContactsContract.Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);
        contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
        contentValues.put(StructuredPostal.FORMATTED_ADDRESS, location);
        try {
            ContactsSyncAdapterService.mContentResolver.insert(ContactsContract.Data.CONTENT_URI, contentValues);
            //	mContentResolver.applyBatch(ContactsContract.AUTHORITY,	operationList);
        } catch (Exception e) {
            e.printStackTrace();
            //Log.e("ERROR:" , e.^);
        }
    }

}
 
Example #27
Source File: InsertContactsCommand.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * Factory method that creates a ContentValues containing the data
 * associated with a RawContact.
 */
private ContentValues makeRawContactData(String displayName,
                                         Uri rawContactUri) {
    ContentValues values = new ContentValues();
    values.put(Data.RAW_CONTACT_ID,
               ContentUris.parseId(rawContactUri));
    values.put(Data.MIMETYPE,
               StructuredName.CONTENT_ITEM_TYPE);
    values.put(StructuredName.DISPLAY_NAME,
               displayName);
    return values;
}
 
Example #28
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
public static void updateContactPhoto(ContentResolver c, long rawContactId, Photo pic, boolean primary){
	ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
	

	
	//insert new picture
	try {
		if(pic.data != null) {
               //delete old picture
               String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId
                       + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";
               Log.i(TAG, "Deleting picture: "+where);

               ContentProviderOperation.Builder builder = ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI);
               builder.withSelection(where, null);
               operationList.add(builder.build());
			builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
			builder.withValue(ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID, rawContactId);
			builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
			builder.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, pic.data);
			builder.withValue(ContactsContract.Data.SYNC2, String.valueOf(pic.timestamp));
			builder.withValue(ContactsContract.Data.SYNC3, pic.url);
               if (primary)
			    builder.withValue(ContactsContract.Data.IS_SUPER_PRIMARY, 1);
			operationList.add(builder.build());

			
		}
		c.applyBatch(ContactsContract.AUTHORITY,	operationList);

	} catch (Exception e) {
		// TODO Auto-generated catch block
		Log.e("ERROR:" , e.toString());
	}


}
 
Example #29
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
public static void removeContactLocations(Context c, Account account){
	ContactsSyncAdapterService.mContentResolver = c.getContentResolver();
	HashMap<String, ContactsSyncAdapterService.SyncEntry> localContacts = ContactsSyncAdapterService.getLocalContacts(account);
	for (ContactsSyncAdapterService.SyncEntry s : localContacts.values()){
		ContactsSyncAdapterService.mContentResolver.delete(ContactsContract.Data.CONTENT_URI, ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.Data.RAW_CONTACT_ID + " = " + s.raw_id, null); 
	}			
	
}
 
Example #30
Source File: HoneycombMR1Util.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the dataCursor for ContactPicker and PhoneNumberPicker (used for Email and Phone).
 */
public static Cursor getDataCursor(String id, Activity activityContext, String[] dataProjection) {
  Cursor dataCursor = activityContext.getContentResolver().query(
      Data.CONTENT_URI,
      dataProjection,
      Data.CONTACT_ID + "=? AND (" + Data.MIMETYPE + "=? OR " + Data.MIMETYPE + "=?)",
      new String[] {id, Phone.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE},
      null);
  return dataCursor;
}