Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

java - Android 2.2 Read SMS Inbox messages

I'm able to read SMS Inbox and display all messages. I have two problems. The first one is that the person field is always NULL.

This is my query to the "content://sms/inbox".

Cursor cursor = context.getContentResolver().query(SMS_INBOX_CONTENT_URI,
           new String[] { "_id", "thread_id", "address", "person", "date", "body" },
                     null,
                     null,
                     SORT_ORDER);

The person field is always NULL. Is there a way to retrieve the actual display name for this SMS message? Is there a join to another table to retrieve display name?

Second, when I tested on my phone, I noticed that my SMS messages are not included in the query. Why is that so? Is it possible to fix this?

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
The person field is always NULL. Is there a way to retrieve the actual display name for


this SMS message? Is there a join to another table to retrieve display name?

For display name you have use another query and cursor or you can join the query to fetch the name of the person but sometime you didn't get the name because that person contact not saved in your contact list or any another organization or company will send the message then you didn't get the name so at that time can query on contact table to fetch the name if found then you can display it otherwise display the address as default.

In this you got the address that was the sender address as in number format so you need to pass this number in the contact query to retrieve the name of that person


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...