Reading a message in inbox from a particular contact - android

I want to read sms from my inbox. Here i want to read a specific message. Suppose mark has sent me a message i just want to make a query which will return the cursor indicating only Mark message .i have tried something like this but it is not working for me
Cursor cursor = contentResolverSender.query(
Uri.parse("content://sms/inbox"), null,"address =?"
,smsNo, null);

Related

Android SMS how to only show latest message per contact and count conversation of a sender [duplicate]

I am trying to create an sms conversation list. I am using this code to get a cursor:
Cursor cursor = activity.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
The problem is that when I use the cursor, I get multiple messages from one contact. I am trying to get only the most recent message from all contacts so that I can show them in a recyclerview as a list of conversations.
Thanks in advance!
Querying the "content://sms/conversations" URI (Telephony.Sms.Conversations.CONTENT_URI) will return a summary of each conversation, with the "snippet" column (Telephony.Sms.Conversations.SNIPPET) being the last message in each.
This query will also return with a "msg_count" column (Telephony.Sms.Conversations.MESSAGE_COUNT) - which is pretty self-explanatory - and a "thread_id" column (Telephony.Sms.Conversations.THREAD_ID), which can be used to retrieve a complete conversation, by querying with that ID appended to the conversations URI. For example:
String threadId = ...
Uri convoUri = Telephony.Sms.Conversations.CONTENT_URI
.buildUpon().appendPath(threadId).build();
Do note that these queries will return only SMS messages. If you want MMS as well, Telephony.Mms and Telephony.MmsSms have similar URIs.

How to get only most recent SMS to use in conversation view?

I am trying to create an sms conversation list. I am using this code to get a cursor:
Cursor cursor = activity.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
The problem is that when I use the cursor, I get multiple messages from one contact. I am trying to get only the most recent message from all contacts so that I can show them in a recyclerview as a list of conversations.
Thanks in advance!
Querying the "content://sms/conversations" URI (Telephony.Sms.Conversations.CONTENT_URI) will return a summary of each conversation, with the "snippet" column (Telephony.Sms.Conversations.SNIPPET) being the last message in each.
This query will also return with a "msg_count" column (Telephony.Sms.Conversations.MESSAGE_COUNT) - which is pretty self-explanatory - and a "thread_id" column (Telephony.Sms.Conversations.THREAD_ID), which can be used to retrieve a complete conversation, by querying with that ID appended to the conversations URI. For example:
String threadId = ...
Uri convoUri = Telephony.Sms.Conversations.CONTENT_URI
.buildUpon().appendPath(threadId).build();
Do note that these queries will return only SMS messages. If you want MMS as well, Telephony.Mms and Telephony.MmsSms have similar URIs.

Looking for a common Contact ID between Telephony.Sms and CallLog.Calls

Goal: I'm trying to group SMS and calls from same (known) contacts.
I read SMS using Telephony.Sms.Inbox.CONTENT_URI and Telephone.Sms.Sent.CONTENT_URI.
I read calls using CallLog.Calls.CONTENT_UTI.
I get the contact's ID by following android is CallLog.Calls._ID the same with the contact id?: using Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, phoneNumber).
Now, having this PhoneLookup._ID, I want to list SMS from that contact.
Sadly Telephony.Sms.PERSON does not seem to store the same contact ID.
Question: How could I list SMS from that PhoneLookup._ID or if not possible, how could I achieve what I want: list SMS and calls from the same contact.
PS: Telephony.TextBasedSmsColumns.PERSON seems to refer the the deprecated Contacts.People API...
Telephony.Sms.PERSON actually matchs ContactsContract.DataColumns.RAW_CONTACT_ID.
So I used:
final Cursor cursor = getContentResolver()
.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
projection, selection, null, null);
Reading ContactsContract.DataColumns.RAW_CONTACT_ID.
https://developer.android.com/reference/android/provider/ContactsContract.DataColumns.html#RAW_CONTACT_ID

How to get unread message in my SMS app android

I have created an SMS app for all versions. I am using the cursor adapter for showing the Message and number. Things are working fine except that I am not able to differentiate the new messages?
How to fix this SMS unread part? I would like to BOLD them when I receive it. But I don't know how what is received.
What I am doing now:
In my SMS receiver I store the new numbers to local DB and then compare them with the SMS content provider. This works just fine, but then takes a lot of time to load the messages.
How to fix this up?
Thanks!
I solved the problem with a few trial and errors..
Got the Read value for particular number and corresponding message( if "0" then bold them according).
To mark read I did the following:
Uri uri = Uri.parse("content://sms/inbox");
String selection = "address = ? AND body = ? AND read = ?";
String[] selectionArgs = {from, body, "0"};
ContentValues values = new ContentValues();
values.put("read", true);
context.getContentResolver().update(uri, values, selection, selectionArgs);
Hope it helps for people who are looking for solution...

Delete the call/sms log history for specific numbers?

in my app i want to delete the sms's/calls of specific numbers i am new to android can any body help me
For calls: use content provider described here: http://d.android.com/reference/android/provider/CallLog.Calls.html
I'm not sure about SMS.
I use this to delete a particular message from the SMS inbox:
//Delete entire SMS thread.
getContext().getContentResolver().delete(
Uri.parse("content://sms/conversations/" + threadID),
null,
null);
//Delete single message.
getContext().getContentResolver().delete(
Uri.parse("content://sms/" + messageID),
null,
null);
These work for me given a valid Thread ID or Message ID.

Categories

Resources