如何预先填充“添加联系人”? Android 2.1 中带有姓氏字段的活动?
我想显示预先填充了姓氏(也称为“姓氏”和“姓氏”)的“添加联系人”活动。目前我只能让它填充名字。这是我的代码:
Intent intentAddContact = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);
intentAddContact.putExtra(ContactsContract.Intents.Insert.NAME, "Mickey Mouse");
intentAddContact.putExtra(ContactsContract.Intents.Insert.PHONE,"01234567891");
intentAddContact.putExtra(ContactsContract.Intents.Insert.EMAIL, "[email protected]");
startActivityForResult(intentAddContact, ADD_CONTACT_REQUEST);
这会将“米老鼠”放在名字字段中。我需要在名字中添加“Mickey”,在姓氏中添加“Mouse”。我的应用程序需要在 Android 2.1(API 级别 7)上运行。
I would like to show the 'Add contact' activity prepopulated with a last name (also known as "family name" and "surname"). Currently I can only get it to populate the first name. Here's my code:
Intent intentAddContact = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);
intentAddContact.putExtra(ContactsContract.Intents.Insert.NAME, "Mickey Mouse");
intentAddContact.putExtra(ContactsContract.Intents.Insert.PHONE,"01234567891");
intentAddContact.putExtra(ContactsContract.Intents.Insert.EMAIL, "[email protected]");
startActivityForResult(intentAddContact, ADD_CONTACT_REQUEST);
This puts "Mickey Mouse" in the first name field. I need "Mickey" to go in the first name and "Mouse" to go in the last name. My app needs to run on Android 2.1 (API level 7).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,AOSP 中的库存“添加联系人”活动似乎仅支持提供全名(请参阅源代码
EditContactActivity.createContact()
和EntityModifier.parseExtras()
)。近似您想要的一种方法是将联系人信息直接插入提供程序,然后启动“编辑联系人”活动,如下所示:
与“添加”方法相比,使用此“插入和编辑”机制的一个显着区别是,如果已经存在具有匹配数据的现有联系人,则提供程序中的聚合过程将更有可能阻止我们创建新联系人。
Unfortunately, it seems that the stock "Add Contact" activity in AOSP only support the full name to be supplied (see source code for
EditContactActivity.createContact()
andEntityModifier.parseExtras()
).One way to approximate what you want is to insert the contact information into the provider directly and then launch the "Edit Contact" activity as follow:
One notable difference using this "insert and edit" mechanism compared to the "add" method is that the aggregation process in the provider will be more likely to prevent us from creating a new contact if an existing one with matching data already existed.