android - 如何获取联系人的主要电子邮件地址

标签 android

你好,

我可以使用以下方法获取接触光标:

Cursor cursor = context.getContentResolver().query(People.CONTENT_URI,
                new String[] {People._ID, People.PRIMARY_EMAIL_ID},
                selection, null, null);

然后我尝试使用以下方法获取实际的电子邮件地址:

 String emailID = cursor.getString(PEOPLE_PRIMARY_EMAIL_ID_INDEX);
 if (Integer.parseInt(emailID) != -1) {
      Cursor cursor2 = context.getContentResolver().query(Uri.withAppendedPath(ContactMethods.CONTENT_URI, emailID), new String[] {ContactMethods.DATA}, null, null, null);

  // cursor2 count is always 0
}
}

有人知道吗?

最佳答案

这是未经测试的,但也许是这样的?

Cursor cursor2 = context.getContentResolver().query(ContactMethods.CONTENT_EMAIL_URI, new String[] { ContactMethods.DATA }, "contact_methods._id=?", new String[] { emailID }, null);

关于android - 如何获取联系人的主要电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2009943/

相关文章:

java - getDatabase 递归调用 sqlite insert 和 getReadableDatabase()

java - @Entity 与 @Persistencecapable

android - Facebook Android SDK 4.2.4 无法登录并且 isLogged 使用 Unity 4.3 返回 false

android - ExpandableListView OnGroupCollapseListener - 崩溃发生之前的任何监听器/观察器?

android - 更改后如何同步android repo?

java - Intent android studio无法运行的原因

android - 如何在 android 中测量 View 或 View 组膨胀时间?

android - 无法使用 cast-android-sample 使 MPEG-DASH 工作

android - 处理 Android 设备关闭(ISSUE : The intent is received only the first time)

Android Facebook SDK "new permissions for a session that has pending request"错误