2010-05-06 96 views
0

我正在开发Android 1.6中的应用程序(不能使用2.0或更旧版本)。以编程方式添加的新联系人在联系人应用程序中不可见

我的手机上添加新的联系人如下:

ContentValues contentValues = new ContentValues(); 
contentValues.put(Contacts.People.NAME, name); 

Uri contactUri = this.getContentResolver().insert(Contacts.People.CONTENT_URI, contentValues); 

在那之后,我以同样的方式添加电话号码。它的工作原理,因为我能看到与下面的代码添加新联系人:

Intent intent = new Intent(Intent.ACTION_VIEW, contactUri); 
this.startActivity(intent); 

我的问题是,添加和查看新的接触后,我看不出它在联系人应用程序,除非我同步我的所有联系人(我也用联系人的名字进行了搜索,发现它,但它没有被添加到联系人列表中)。

如何以编程方式更新联系人,以便立即将我的新联系人添加到联系人应用程序中?

谢谢!

回答

3

我找到了答案:添加新联系人(插入)后,将其添加到与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); 
+0

[Contacts.People] 这种类型的myContactsGroup已过时,任何新的建议? – RRTW 2012-05-11 09:26:58

相关问题