I'm developing an app which requires threaded sms. I was able to retrieve contents from inbox, but in the threaded view sms must be filled with both inbox and sent items.
Separately both content://sms/inbox and content://sms/sent are working well.
How do I join contents from two URI's and order by time?
Can I use content://sms/all?
Null value is returned for cursor when ALL CONTENT URI is used.
How to do this?
At last found the answer for this..
content://sms/all
is something which i couldnt find.
But for retrieving both sent and received we can use
Uri selectUri = Uri.parse("content://sms/");
Cursor cur = getContentResolver().query(selectUri,null,"thread_id="+threadid, null,"DATE desc");
This snippet fetches and displays in descending order
Thanks all
I had the same issue. For this,you can use MatrixCursor.What I have done is-
Get all sms from content://sms/inbox for a thread_id
Get all sms from content://sms/sent for a thread_id
Maintain an arraylist and sort them in the order you want(I did this using bubble sort)
Now define and initialize the matrixCursor
(Refer this: http://groups.google.com/group/android-developers/browse_thread/thread/470dd3a1703848eb/d7e70618ce413261?q=MatrixCursor+join+two+tables for MatrixCursor )
Add all the sorted records to your matrixCursor
(Please note that adding this record should be in the sequence of at what time and from which folder(inbox or sent) they come.MatrixCursor simply lets you create a custom cursor so you need to maintain the sequence.)
Related
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.
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.
I'm implementing the methods discussed here: How to Read MMS Data in Android?
I'm trying to read SMS and MMS into a single listview. I'm doing pretty well, but when I try to sort I'm getting all of the SMS sorted together followed by all of the MMS sorted together.
Here is my code:
Cursor smsCursor = getContentResolver().query(Uri.parse("content://mms-sms/conversations/"), null, null, null, "date DESC");
Can anyone tell me how to combine the two sources or how to combine the MMS into the SMS conversations like the built in Android app does?
Edit: I noticed that the date of SMS has several more digits than the dates of MMS.
Edit 2: Adding "julianday()" like so:
Cursor smsCursor = getContentResolver().query(Uri.parse("content://mms-sms/conversations/"), null, null, null, "julianday(date) DESC");
Makes the MMS appear at the top of the list.
try normalized_date desc instead of date desc for the order.
It should work.
The real problem here seem's to be that in the Database, the date is not stored exactly the same Way for SMS and MMS.
So you'll need to first query the database looking just for the "date" field.
(Not normalized_date that would crash on some devices).
Then sort your list programmaticly in Java, taking in account that for the MMS,
the date needs to be multiplied by 1000 as stated here :
How do the retrieve the date of the mms from content://mms.*
Or here
mms sent/recive date is always in 1970
Let's say that I have a Cursor that has 50 records in it and it is bound to a ListView using a ViewBinder. I'd like to find a specific row(example: _id 35) and make sure that record is visible to the user on the android device. Is this possible?
What is find a specific row? You can call Cursor c = (Cursor) adapter.getItem(position) to get a cursor pointing to the position the user selected. Then you can retrieve the data like cursor.getString(cursor.getColumnIndexOrThrow("columnName")).
I got following problem, I need to use a Content Provider to read a
Database of an other App.
first I want all rows, and after analyzing the data only e.g. the rows
from _id = 1, 3 and 5.
how can I call a Content provider and select only these rows?
or is it possible to create a subset Cursor form an given Cursor?
Thanks in advance.
If you're talking to another app, I assume you're querying the other app's ContentProvider to get the data from them in the first place.
In this situation, the cleanest answer seems not to build your own ContentProvider that filters/wraps theirs. Instead query their ContentProvider from your application directly, and use the select clause in your query() to specify the conditions that define the subset of data you want to be given.