我想获取一位联系人的所有消息。我有联系人 ID _id
,所以我已经做了这样的事情:
private void displayMessages() {
ContentResolver cr = this.getContentResolver();
try {
Cursor cursor = cr.query(Uri.parse("content://mms-sms/conversations"), new String[]{"*"}, this.contID + "= _id" , null, null); //contID is the unique ID for one contact in our android.
while (cursor.moveToNext()) {
System.out.println("Number: " + cursor.getString(cursor.getColumnIndexOrThrow("address")));
System.out.println("Body : " + cursor.getString(cursor.getColumnIndexOrThrow("body")));
}
cursor.close();
}
catch (Exception e) {
System.out.print("ERROR");
}
我问过类似的问题
SELECT * FROM content://mms-sms/conversations WHERE _id = contID
如您所见,在我的查询中,我向系统询问来自一个联系人(我知道的用户 ID)的消息,但我只能显示最后一条消息 body。所以我认为是否存在其他查询以获取来自一个用户的所有消息?
有什么想法吗???
最佳答案
我怀疑在这种情况下 _id
是您要向其发送短信/彩信的联系人的 ID,而是线程的 ID。您可能希望用于查询子句的列是 RECIPIENT_IDS .出于调试目的,请尝试不使用 where 子句并转储游标以分析结果
Cursor cursor = cr.query(Uri.parse("content://mms-sms/conversations"), new String[]{"*"}, null , null, null);
DatabaseUtils.dumpCursor(cursor);
关于android - 获取与 Android 查询的完整对话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32920843/