Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获取联系人的主要电子邮件地址_Android - Fatal编程技术网

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

Android 如何获取联系人的主要电子邮件地址,android,Android,嗨 我可以通过以下方式获取联系人光标: Cursor cursor = context.getContentResolver().query(People.CONTENT_URI, new String[] {People._ID, People.PRIMARY_EMAIL_ID}, selection, null, null); 然后我尝试使用以下方法获取实际电子邮件地址: String emailID = cursor.ge

我可以通过以下方式获取联系人光标:

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);

把你之前的几个问题标记为先被接受怎么样?伙计们。你能把完整的源代码,如何获得主要的电子邮件地址?我真的很感谢你的帖子。谢谢