当我查询“content://sms/”内容提供商并从地址栏中提取信息时;我总是得到消息“来自”或“发送到”的电话号码。如果我收到一条消息,那么地址就是对方电话号码。当我发送消息时,地址就是我要发送到的消息。
如何在不查询相应收件箱/已发送文件夹的情况下区分“content://sms/”文件夹中的邮件是已发送邮件还是已接收邮件?
Uri uri = Uri.parse("content://sms/");
String[] columns = new String[] { "_id", "thread_id", "address", "person", "date", "body" };
String selection = "thread_id = " + threadId;
String sortOrder = "date DESC";
String limit = "LIMIT " + String.valueOf(mItemsOnPage);
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String deviceNumber = tm.getLine1Number();
Cursor cursor = getContentResolver().query(uri, columns, selection, null,
sortOrder + " " + limit);
if (cursor != null) {
cursor.moveToLast();
while (!cursor.isBeforeFirst()) {
long messageId = cursor.getLong(0);
String address = cursor.getString(2);
long date = cursor.getLong(4);
String body = cursor.getString(5);
long person = cursor.getLong(3);
cursor.moveToPrevious();
}
}
cursor.close();
最佳答案
您需要在查询中包含type
列。它包含一个long,指示您正在处理接收的(type == 1
)还是发送的(type == 2
)消息。
这样您就会知道如何解释地址栏。
关于android - 内容://sms/address column not always return "sender' s"number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9343059/