Android add multiple contact phone numbers

using the Android SDK> 5, I create a contact by running the ACTION_INSERT action. I want to add several phone numbers (work, home, etc.) for the contact using the following code:

Intent newIntent = new Intent(Intent.ACTION_INSERT, 
          ContactsContract.Contacts.CONTENT_URI); 

for(ContactInfo.Phone p : phones)
      {

       newIntent.putExtra(ContactsContract.Intents.Insert.PHONE, p.number);
       newIntent.putExtra(ContactsContract.Intents.Insert.PHONE_ISPRIMARY, p.isPrimary ? new Integer(1) : null);
       newIntent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, unconvertPhoneType(p.type));

      }

(unconvertPhoneType () is a function to get the type CommonDataKinds.Phone.TYPE_XXX)

I have only one example inserted in contact. What is wrong with this?

In addition, in LogCat logs, I also have the following error:

12-14 11: 09: 03.015: WARN / Bundle (1724): Key phone_type expected String, but the value was java.lang.Integer. The default value has been returned.

it looks like it comes from PHONE_TYPE, however CommonDataKinds.Phone.TYPE_XXX is of type integer, so I'm not sure ... What is the reason for this?

Thank!

+3
1

- , String, . . String.

, , "".

// Add a phone number for Abraham Lincoln.  Begin with the URI for
// the new  record     just returned by insert(); it ends with the _ID
// of the new record, so we don't have to add the ID ourselves.
// Then append the designation for the phone table to this URI,
// and use the resulting URI to insert the phone number.
phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);
values.clear(); 
values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE); 
values.put(People.Phones.NUMBER, "1233214567");
getContentResolver().insert(phoneUri, values);

, .

0

Source: https://habr.com/ru/post/1780318/


All Articles