When I query the "content://sms/" content provider and pull information from the address column; I always get the phone number that the message is "from" or "sent to". If I receive a message, then address is the number from the other person's phone. When I send a message, then address is the message I am sending to.
How do I differentiate if a message in "content://sms/" folder is a sent message or received message without querying the respective inbox/sent folders?
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();