新的编程方式添加联系,联系人应用程序中不可见 [英] New programmatically added contact not visible in Contacts application
问题描述
我在Android 1.6的深化发展的应用程序(而不能使用2.0或以上)。
I'm developping an application in Android 1.6 (and can't use 2.0 or older).
我的手机上添加新的联系人如下:
I add a new contact on my phone as following :
ContentValues contentValues = new ContentValues();
contentValues.put(Contacts.People.NAME, name);
Uri contactUri = this.getContentResolver().insert(Contacts.People.CONTENT_URI, contentValues);
此后,我以相同的方式添加电话号码。它的工作原理,因为我看见有以下code新添加的联系人:
After that, I add phone numbers in the same way. It works as I am able to view the new added contact with following code :
Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
this.startActivity(intent);
我的问题是,添加和查看新的接触后,我无法看到它在联系人应用程序,除非我同步我的所有联系人(我也做了与联系人的姓名进行搜索,发现了它,但它不是在联系人列表中添加)。
My problem is that, after adding and viewing the new contact, I can't see it in Contacts application unless I synchronized all my contacts (I also did a search with the contact's name, found it, nevertheless it wasn't added in contacts list).
我如何编程方式更新,以便立即在联系人应用程序添加我的新联系人的联系人?
How can I programmatically update the contacts in order to immediately have my new contact added in Contacts application ?
感谢您!
推荐答案
我找到了答案:添加新联系人(插入)后,添加它与来myContactsGroup Contacts.People.addToMyContactsGroup()方法:
I found the answer : after adding new contact (insert), add it to myContactsGroup with Contacts.People.addToMyContactsGroup() method :
// get new contact id :
int contactId = Integer.valueOf(contactUri.toString().substring(contactUri.toString().lastIndexOf("/")+1));
// add the new contact to myContactsGroup to have it in Contacts Application :
Contacts.People.addToMyContactsGroup(this.getContentResolver(), contactId);
这篇关于新的编程方式添加联系,联系人应用程序中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!