2

I use Android 1.6. I'd like to query "content://sms/inbox". How to implement it?

soclose
  • 2,773
  • 12
  • 51
  • 60

2 Answers2

5

Part of the SDK or not, I can't see any way to access SMS data other than using content://sms/inbox

String folder = "content://sms/inbox" -or- "content://sms/sent"

Uri mSmsQueryUri = Uri.parse(folder);
String columns[] = new String[] {"person", "address", "body", "date","status" 
String sortOrder = "date ASC"; 
Cursor c = _context.getContentResolver().query(mSmsQueryUri, columns, where, null, sortOrder);

This will give you a Cursor to access what you need.

Take a look at gTalkSMS. The file to look at for SMS database queries is the SmsMmsManager.

Flow
  • 23,572
  • 15
  • 99
  • 156
eternalmatt
  • 3,524
  • 4
  • 25
  • 25
2

This is not part of the Android SDK. Please do not use it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • @CommonsWare: What do you mean? – Macarse Apr 30 '10 at 11:55
  • 1
    I mean that the SMS application, and its inbox, and the string `"content://sms/inbox"` are not part of the Android SDK. Please do not use them from an SDK application. If you are modifying the firmware for distribution on your own phones, that is fine, but I rather doubt that is what the OP is seeking to do. http://www.androidguys.com/2009/12/14/code-pollution-reaching-past-the-sdk/ – CommonsWare Apr 30 '10 at 12:14
  • 2
    If usage of these Uris is not recommended, what's the preferred way of accessing SMS? If there's no suggested way of accessing SMS, then how come there are WRITE_SMS, READ_SMS, RECEIVE_SMS permissions? Thanks. – pm_labs May 01 '13 at 02:33
  • 3
    @paul_sns: " how come there are WRITE_SMS, READ_SMS, RECEIVE_SMS permissions?" -- when Android was originally created, before its release, there was no SDK. In 2006 (or perhaps early 2007), when they decided to create an SDK, they effectively had to take a meat cleaver to the existing code base, to create the boundary between API implementation and API usage. As whenever you cut with a meat cleaver, accuracy is limited, and so some things, like SMS, landed on both sides of the API boundary. Hence, we have permissions for things we have no documented/supported means to actually do. – CommonsWare May 01 '13 at 11:13
  • @CommonsWare is there any case in which user have the sms and content://sms/inbox cursor will give 0 count? – ice spirit Oct 15 '20 at 08:44
  • @icespirit: Well, this answer was from 2010, and the last comments prior to yours from 2013. It is now 2020, and you should be using the `Sms` `Uri` values provided (finally!) in the SDK. Beyond that, perhaps the user's SMS client is saving messages somewhere else, or some permission issue is preventing you from seeing the contents of the provider. – CommonsWare Oct 15 '20 at 10:38