使用多个电话号码通过意图添加新联系人 [英] Add new contact via intent with multiple phone numbers
本文介绍了使用多个电话号码通过意图添加新联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用ContactsContract.Intents.Insert
添加新联系人.但是问题是我不知道可以有多少个电话号码.据我了解,我只能使用PHONE
,SECONDARY_PHONE
,TERTIARY_PHONE
常量传递三个电话号码.有什么办法可以传递三个以上的数字?
I want to add a new contact using ContactsContract.Intents.Insert
. But the problem is that I don't know how many phone numbers can be. And as I understand I can pass only three phone numbers using PHONE
, SECONDARY_PHONE
, TERTIARY_PHONE
constants. Is there any way to pass more than three numbers?
推荐答案
找到了解决方案.它包含使用ContentValues:
Found a solution. It consists in using ContentValues:
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
//Filling data with phone numbers
for (int i = 0; i < numberOfPhones; i++) {
ContentValues row = new ContentValues();
row.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
row.put(Phone.NUMBER, PhonesNumberList.get(i));
row.put(Phone.TYPE, Phone.TYPE_WORK);
data.add(row);
}
contactIntent.putExtra(ContactsContract.Intents.Insert.NAME, mName);
contactIntent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);
startActivity(contactIntent);
这篇关于使用多个电话号码通过意图添加新联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文