2

I am trying to create a ContentObserver that will inform me when an SMS is sent from my device. When I use the following my onChange() gets called:

public static final Uri uriSMS = Uri.parse("content://sms");

However, when I try to limit it to just sent SMS messages using this:

public static final Uri uriSMS = Uri.parse("content://sms/sent");

it does not work; the onChange() method simply doesn't get called. Can anyone help me troubleshoot this?

gonzobrains
  • 7,856
  • 14
  • 81
  • 132

1 Answers1

2

Use

public static final Uri uriSMS = Uri.parse("content://sms");

and check the type of the cursor

Here is an example code.

Lucifer
  • 29,392
  • 25
  • 90
  • 143
stinepike
  • 54,068
  • 14
  • 92
  • 112
  • I have seen other SO questions where people were using content://sms/sent. Is that no longer supported? – gonzobrains May 11 '13 at 04:48
  • I think I saw that sample during my research but haven't tried it yet. I will report back here after I have tested it. Thanks. – gonzobrains May 11 '13 at 04:49
  • it appears to get called now, but it is called multiple times. Why is this? I only want to handle it once, so how can I narrow down my test in the onChange() event so that I'm not processing it multiple times? – gonzobrains May 14 '13 at 00:22
  • have you unregistered the observer? – stinepike May 14 '13 at 11:13
  • also check that .. http://stackoverflow.com/questions/6026547/android-content-observers-onchange-method-is-called-multiple-times – stinepike May 14 '13 at 11:15
  • I unregister it in onDestroy(). – gonzobrains May 14 '13 at 13:30
  • a normal solution is to use a timer. Check the time interval between 2 call. If the interval is too short then do not perform the operation – stinepike May 14 '13 at 14:05