update contact details on Android

前端 未结 3 419
再見小時候
再見小時候 2020-12-20 10:49

I would like my code to update contact details (like name, phone number, email, organization details, etc) in the android contact book. I was successful in

相关标签:
3条回答
  • 2020-12-20 11:10
    String[] projection = new String[] { ContactsContract.RawContacts._ID };
            String where = ContactsContract.RawContacts.CONTACT_ID + " = ?";
            String[] selection = new String[] { String.valueOf(1) };
            Cursor c = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, projection, where, selection, null);
            c.moveToFirst();
            for(int i=0;i<c.getCount();i++)
            {
                Log.e("id",""+c.getString(0));
                c.moveToNext();
            }
    
    
    
            ContentValues values = new ContentValues();
            values.clear();
            values.put(ContactsContract.RawContacts._ID , 0);
            getContentResolver().update(ContactsContract.RawContacts.CONTENT_URI, values,ContactsContract.RawContacts._ID + "+ ?",new String[] { String.valueOf(1) });
    
    0 讨论(0)
  • 2020-12-20 11:17

    I spent a lot of time trying to update the company and title information. The following now works for me.

    Uri workUri = Uri.withAppendedPath(contactUri, android.provider.Contacts.Organizations.CONTENT_DIRECTORY);
                values.clear();
                values.put(android.provider.Contacts.Organizations.COMPANY, "company");
                values.put(android.provider.Contacts.Organizations.TYPE, android.provider.Contacts.Organizations.TYPE_WORK);
                values.put(android.provider.Contacts.Organizations.TITLE, "job title");
                values.put(android.provider.Contacts.Organizations.ISPRIMARY, 1);
                getContentResolver().insert(workUri, values); 
    
    0 讨论(0)
  • 2020-12-20 11:21

    In order to update any data in the contacts you need to know the existing id for that fields. Then I used the Builder class to obtain separate ContentProviderOperation objects for the various fields I wanted to update, add them to an arrayList and then use the ContentProvider.applyBatch() method

    0 讨论(0)
提交回复
热议问题