Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...