1

I want to access the content provider for sms in Android version 4.4 onwards. I know about the following way

Uri sms = Uri.parse("content://sms/");

This doesn't seem to work for 4.4. Can anyone help and tell me the right path?

Ekta
  • 338
  • 2
  • 9
  • 26

1 Answers1

0

Try below code Ekta:

Cursor c = cr.query(Telephony.Sms.Inbox.CONTENT_URI, // Official CONTENT_URI from docs
                      new String[] { Telephony.Sms.Inbox.BODY }, // Select body text
                      null,
                      null,
                      Telephony.Sms.Inbox.DEFAULT_SORT_ORDER // Default sort order);
Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
  • cr is the content resolver? Also it says Telephony cannot be resolved to a variable. It doesn't even suggest an import. – Ekta May 13 '14 at 10:36
  • just check is your application are belongs to api level 19? – Pratik Dasa May 13 '14 at 10:41
  • Yes that was the problem. I'm updating it, then I'll test your code. Also can you tell me a way of pushing values into this db? – Ekta May 13 '14 at 10:44
  • hmmm yup grt, newbie in andriod? – Pratik Dasa May 13 '14 at 10:45
  • Nope. It takes time to download and update. Will let you know. – Ekta May 13 '14 at 11:02
  • hmmmm ok let me knw...frm where r u? – Pratik Dasa May 13 '14 at 11:09
  • Yes. It did the job that it talks about sadly that was not what I was looking for. Anyways Thanks a lot. I'll accept the answer. :) – Ekta May 20 '14 at 06:37
  • Telephony.Sms.Inbox.CONTENT_URI provides illegal argument exception Unknown URL while deleting messages from inbox. Any idea how it can be resolved? – seema Apr 22 '15 at 06:53
  • try { int count = mContext.getContentResolver().delete(Telephony.Sms.Inbox.CONTENT_URI, "thread_id=?", new String[] { String.valueOf(threadId) }); Log.e("", "in if block: " + threadId + " " + count); toastMsg = count + " messages deleted"; } catch (Exception ex) { Log.e("", "in exception block: " + ex.getMessage()); toastMsg = ex.getMessage(); } } I have used this code block. – seema Apr 22 '15 at 10:12
  • @seema means you want to delete the messages from inbox?? – Pratik Dasa Apr 22 '15 at 10:14
  • yes, I have to delete sms from inbox. My app is default sms app. – seema Apr 22 '15 at 12:02
  • Also, i am able to read using URI content://sms, but not able to delete using this URI. – seema Apr 22 '15 at 12:41
  • @seema okay, let me check it out. – Pratik Dasa Apr 22 '15 at 12:46
  • @seema kitkat not allowed you to delete messages. – Pratik Dasa Apr 22 '15 at 12:58
  • http://stackoverflow.com/questions/25988574/delete-sms-from-android-on-4-4-4-affected-rows-0zero-after-deleted http://stackoverflow.com/questions/24168336/unable-to-delete-sms-programmatically – Pratik Dasa Apr 22 '15 at 12:59
  • I have done this in lolipop 5.0.1 successfully with Uri content://sms... Then how come it is not possible in kitkat? – seema Apr 22 '15 at 16:54
  • I have made my app is default sms app, and as far as i know, default sms app can do so. – seema Apr 22 '15 at 16:55
  • @seema not sure I have also read it, but I think some devices are not supporting, try with some other device. – Pratik Dasa Apr 23 '15 at 04:51
  • I checked in same device model (samsung S4).. one with 5.0.2 and second with 4.4.2. It worked in 5.0.2 but not in 4.4.2. So it is not issue with vendors or devices. – seema Apr 23 '15 at 09:05