[英]How To get a specific contact Note from contentresolver?
I need to get a Note of a specific contact which I have his ID and his name. 我需要得到一个特定联系人的便笺,其中包含他的ID和他的名字。 Whatever I'm trying only gets me NULL at the end and im out of options after trying to find a similar answer on Google and here on SO..
无论我在尝试在Google以及此处找到类似的答案之后,最终只能让我在测试结束时得到NULL,并且使我失去选择。
PLEASE HELP :) This is the code I have: 请帮助:)这是我的代码:
Cursor noteCur = cr.query(ContactsContract.Data.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Note.CONTACT_ID+"='"+id+"'", null, null);
noteCur.moveToFirst();
note = noteCur.getString(
noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
mContactList.get(mContactList.size()-1).setNote(note);//Adding the contact Note
System.out.println("Note " + note);
noteCur.close();
if im adding a contact from my application and specify a Note in the Add method, the Note is being transfered and displayed successfuly 如果即时通讯从我的应用程序添加联系人并在Add方法中指定一个便笺,则该便笺已成功传输并显示
BUT if im trying to get this specific contact's Note after I close and open the application I cant get it's Note and all I get is NULL :( 但是如果我在关闭并打开应用程序后尝试获取此特定联系人的注释,则无法获取注释,而我得到的只是NULL :(
The Note is visible in other contacts application so the problem is how I am trying to get the Note in my own application.. 该注释在其他联系人应用程序中可见,因此问题是我如何尝试在自己的应用程序中获取该注释。
THANK YOU! 谢谢!
Got it if somone is interested.. 如果有人感兴趣的话就知道了。
try {
Cursor cursor = contentResolver.query(
ContactsContract.Data.CONTENT_URI,
null,
CommonDataKinds.Note.CONTACT_ID +" = ?",
new String[]{contactId}, null);
while (cursor.moveToNext())
{
note = cursor.getString(cursor.getColumnIndex(CommonDataKinds.Note.NOTE));
}
System.out.println("Note " + note);
cursor.close();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Where "contactId" is the ID of the specific Contact. 其中,“ contactId”是特定联系人的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.