【问题标题】:New programmatically added contact not visible in Contacts application以编程方式添加的新联系人在联系人应用程序中不可见
【发布时间】:2010-05-06 20:20:59
【问题描述】:

我正在使用 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);

我的问题是,添加并查看新联系人后,除非我同步所有联系人,否则我无法在联系人应用程序中看到它(我也用联系人的姓名进行了搜索,找到了,但它不是添加到联系人列表中)。

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

谢谢!

【问题讨论】:

    标签: android


    【解决方案1】:

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

    【讨论】:

    • [Contacts.People] 这种类型已弃用,有什么新建议吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 2014-08-06
    相关资源
    最近更新 更多