Skip to content Skip to sidebar Skip to footer

Android Get Sms From Inbox, Optimized Way To Read All Messages And Group Them

Hi am implementing a SMS App, now am able to retrieve all messages with their respective contact info like display name, photo uri.. and am displaying them in a custom list where o

Solution 1:

POJO storage is not a great approach since those are required to stay in memory all the time, or else be reloaded causing pain and slowness.

In this case, you should create a Service that updates a sqlite database, and present it as a ContentProvider. The sqlite db should only contain the structure that is not provided by Android, i.e. your Contact/Threads hierarchy, and any data you might be displaying in your list, such as the text of the most recent message.

This thread has a discussion of how to detect new SMS Message arrival/sends, whether from your app or another, which is probably what you really want rather than simply detecting that the user posted a message from your own app. The Service should perform this task, the UI Activity only needs to observe the ContentProvider.

Aside: I wonder how the user will send a message to a contact to whom they have not yet sent a message, since your list only contains contacts who they have sent messages to.

Solution 2:

You might need to provide more detail as to how are you actually approaching towards the direction, in particular how many activities you are having (it seems like there are two).

Assuming there are two of them, in First Activity don't try to catch every single message just get all the thread_Ids and addresses.

Then as the user clicks any of the list items then execute other thread to read all the messages belongs to that thread.

use the following:

UriuriSMSURI= Uri.parse("content://sms/inbox");
Cursorcur= getContentResolver().query(uriSMSURI, null, null, null, null);

for reading inbox and getting thread_Ids and address and store them to some java modal class i.e. DTO

and populate list and as user clicks any of the items pass on the thread_id and then query like this to get all the conversation i.e. thread.

UriuriSMSURI= Uri.parse(Uri.parse("content://sms/conversations/")+ thread_id);
cursor = getContentResolver().query(uriSMSURI, null,"thread_id=?", newString[] { tid }, null);

Post a Comment for "Android Get Sms From Inbox, Optimized Way To Read All Messages And Group Them"