Querying the MMS-SMS conversation - android

I am implementing the methods discussed here How to Read MMS Data in Android
Here is the snippet.
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Uri uri = Uri.parse("content://mms-sms/conversations/");
Cursor query = contentResolver.query(uri, projection, null, null, null);
When I try to get the data through the cursor, I do not get the IDs of the MMS messages. I only get the IDs of the SMS messages. I have two MMS in my inbox and their address "number" do not show up.

Related

How to get only sent messages from specific conversation in Android Studio?

ContentResolver cr = getContentResolver();
String[] projection = new String[]{"body", "ct_t", "_id", "address"};
Uri uri = Uri.parse("content://mms-sms/conversations/" + id);
Cursor c = cr.query(uri, projection, null, null, null);
This queries all messages from a specific conversation and I would like only the sent messages to display as I need to distinguish each party of the conversation.
Is there such a thing as a uri like this:
Uri uri2 = Uri.parse("content://mms-sms/conversations/" + id + "/sent/");
You'll need to add a couple of columns to your projection, and include a selection argument in the query() call.
final String[] projection = {"_id", "address", "body", "ct_t", "type", "msg_box"};
final String selection = "(type = 2 OR msg_box = 2)";
final Uri uri = Uri.parse("content://mms-sms/conversations/" + threadId);
Cursor c = getContentResolver().query(uri, projection, selection, null, null);
An SMS message will have a type value of 2 when it has been sent. An MMS message will have the same value, but in the msg_box column.

How to Differentiate MMS and SMS in android?

How to Differentiate MMS and SMS via MMS/SMS listeners in Android? Because I got SMS counts as in MMS counts?
I am calculating Total MMS as using following code.
Uri mmsInboxUri = Uri.parse("content://mms/inbox");
Uri mmsSentUri = Uri.parse("content://mms/sent");
Cursor mmsInboxCursor = getContentResolver().
query(mmsInboxUri ,new String[] {"_id"}, null, null);
Cursor mmsSentCursor = getContentResolver().
query(mmsSentUri ,new String[] {"_id"}, null, null);
int mmsCount = mmsInboxCursor.getCount() + mmsSentCursor.getCount();
You should check the column ct_t. If it's a MMS it should be equal to application/vnd.vap_multipart.related.

Query does not get MMS messages

I am implementing the method discussed here How to Read MMS Data in Android. Here is the code snippet:
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Uri uri = Uri.parse("content://mms-sms/conversations/");
Cursor query = contentResolver.query(uri, projection, null, null, null);
When I try to get the data through the cursor, I do not get the IDs of the MMS messages. I only get the IDs of the SMS messages.
change your code as:
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Uri MMSSMS_FULL_CONVERSATION_URI = Uri.parse("content://mms-sms/conversations");
Uri uri = MMSSMS_FULL_CONVERSATION_URI.buildUpon().
appendQueryParameter("simple", "true").build();
Cursor query = contentResolver.query(uri, projection, null, null, null);
My code is right. It just needs this code to get the id of the messages
cursor.moveToFirst();
String address = cursor.getString(cursor.getColumnIndex("_id"));

Query with multiple uri's

Uri contactUri1 = Uri.withAppendedPath(
ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number1));
Cursor phones = getContentResolver()
.query(contactUri1, PEOPLE_PROJECTION, null, null, null);
This works. I can get what I need in the cursor given number1.
What I want is to query for multiple numbers and get all the results in the same cursor.
EXAMPLE:
Uri contactUri1 = ...
Uri contactUri2 = ...
Cursor phones = getContentResolver().query(... //Both URI's
Is that possible?

What is the correct CONTENT_URI for the SMS thread table?

I'm attempting to query the SMS thread table, but I don't seem to use the correct URI.
Querying the URI "content://sms/conversations" gives me the columns:
[thread_id, msg_count, snippet]
Querying the URI "content://mms-sms/conversations" gives me the columns:
[body, person, sub, subject, retr_st, type, date, ct_cls, sub_cs,
_id, read, ct_l, tr_id, st, msg_box, thread_id, reply_path_present,
m_cls, read_status, ct_t, status, retr_txt_cs, d_rpt, error_code,
m_id, m_type, v, exp, pri, service_center, address, rr, rpt_a,
resp_txt, locked, resp_st, m_size]
I'm looking for the URI that gives the values from the Threads table in android/provider/Telephony.java - data, recipient_ids, message_count, read, etc...
Thanks
try this
Uri uri = Uri.parse("content://sms/");
you can get what you want like this
Uri uri = Uri.parse("content://sms/");
// List required columns
String[] reqCols = new String[] { "_id", "body" };
// Get Content Resolver object, which will deal with Content Provider
ContentResolver cr = context.getContentResolver();
// Fetch Sent SMS Message from Built-in Content Provider
Cursor cursor = cr.query(uri, reqCols, "address = '" + number + "'", null, null);
// Attached Cursor with adapter and display in listview
adapter = new SimpleCursorAdapter(context, R.layout.single_conversation_view, cursor, new String[] {"body" }, new int[] { R.id.tv_single_conversation_message }, 1);
lv_single_conversation.setAdapter(adapter);
hope it will help you

Categories

Resources