【问题标题】:Getting details of edited contact back using ACTION_EDIT and startActivityForResult()使用 ACTION_EDIT 和 startActivityForResult() 获取已编辑联系人的详细信息
【发布时间】:2015-09-25 08:06:37
【问题描述】:

我正在为我的应用程序维护一个联系人列表。首先,我使用ACTION_PICK 和intent 选择联系人。我将这些联系人与CONTACT_ID 一起保存在我的本地数据库中。现在用户可以选择编辑任何联系人以添加我的应用程序需要的一些额外信息。我用ACTION_EDIT 触发了那个编辑意图。我这里有两个问题

  1. 我将CONTACT_ID 保存到我的数据库中,以便在编辑意图中使用。第一个问题是这个 id 在 edition 之后会改变吗?因为碰巧我无法再次打开同一联系人的联系人编辑器。

  2. 第二个问题是如何读回这个编辑过的联系人的所有详细信息?我在我的onActivityResult() 中找回了这个。我曾尝试使用我在挑选时使用的相同代码,但在编辑时返回的数据结构似乎不同。

【问题讨论】:

  • 你是使用android联系ContentProvider还是你已经创建了你的ContentProvider?
  • 是的,我使用的是默认的!
  • 所以你可以在你的onActivityResult()中使用光标,我会用源代码回复。
  • @RicardoRivaldo 谢谢,我会在有时间的时候看看它并告诉你

标签: android android-intent android-contentprovider android-contacts android-contentresolver


【解决方案1】:

您可以使用光标从联系人中获取任何数据,例如

String[] projection = new String[] {
     ContactsContract.PhoneLookup.DISPLAY_NAME,
     ContactsContract.PhoneLookup._ID};
// query time
Cursor cursor = _context.getContentResolver()
         .query("ContactsContract.Contacts.CONTENT_URI",
                  projection, null, null, null);

if(cursor != null) {
    while ( cursor.moveToNext()) {
        String name = cursor.getString(cursor.getColumnIndex(
                       ContactsContract.PhoneLookup.DISPLAY_NAME));
        // do other stuff
    }
}
cursor.close();

看看https://developer.android.com/training/contacts-provider/retrieve-details.html

【讨论】:

    猜你喜欢
    • 2012-02-21
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    相关资源
    最近更新 更多