Reputation: 2858
How can I query all messages sent by a specific address?
I couldn't find my answer on StackOverflow after many days of searching.
I'm currently getting all messages like this:
Uri uri = Uri.parse("content://sms/");
Cursor managedCursor = getContentResolver().query(uri, null, ("thread_id = " + ThreadID), null, "date ASC");
But this only returns SMS messages (no MMS). I tried changing content://sms/
to content://mms-sms/
but that was unrecognized. I also tried to query content://mms-sms/conversations/xxx
where xxx
is the thread_id but that just gave me a NullPointerException.
I've been searching for a solution to this for days. Other SMS apps such as Go SMS and Sliding Messaging can do it perfectly but I just can't seem to figure it out...
Upvotes: 4
Views: 3210
Reputation: 31
A null
projection argument to content://mms-sms/conversations/xxx
is what's causing the NullPointerException
--- if you explicitly project the columns you want (e.g, {"address", "body", "date"}
), it should work just fine.
However, querying by thread_id
isn't strictly selecting based on the address the message is sent from; if you want that, you should probably look in content://sms/inbox
(which ignores messages you've sent) and use selection arguments to query for the address you're interested in:
Uri uri = Uri.parse("content://sms/inbox");
Cursor managedCursor = getContentResolver().query(uri, null, "address=?", {targetedAddress}, "date ASC");
Upvotes: 3