Android get sms from inbox, optimized way to read all messages and group them

不想你离开。 提交于 2019-12-03 11:04:12
Brane

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.

The VOYOU

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:

Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = 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.

Uri uriSMSURI = Uri.parse(Uri.parse("content://sms/conversations/")+ thread_id);
cursor = getContentResolver().query(uriSMSURI, null,"thread_id=?", new String[] { tid }, null);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!