view raw
KVISH KVISH - 9 months ago 64
Android Question

Android MMS observer

I have the following code:

public class MmsObserver extends ContentObserver {
private Context context;

public MmsObserver(Handler handler) {
this.context = service.getBaseContext();

public void onChange(boolean selfChange) {

Long largestDateCounted = Long.parseLong(UserPreferencesManager.getInstance().getValueFromPreferences(context, context.getString(R.string.preferences_current_counter), "0"));
String filter = "creator != ? and date > ?";
String[] args = new String[]{context.getPackageName(), Long.toString(largestDateCounted)};
Cursor c = context.getContentResolver().query(Constants.Mms, null, filter, args, null);

try {

} catch (Exception e) {
} finally {

I'm trying to observe when user sends/receives an MMS message. However, my observer never gets called. Is there something I'm missing on this? I have read the below:

Android MMS Monitoring

Android MMS Broadcast receiver


here is how i'm running the observer:

mmsContent = new MmsObserver(new Handler());
getContentResolver().registerContentObserver(Constants.Mms, true, mmsContent);


When registering a ContentObserver for MMS, the URI needs to be content://mms-sms/, at least on older Android versions. For some reason, content://mms/ won't work for a ContentObserver, other than possibly firing on changes to draft messages.

Do note that this will cause the Observer to fire for changes to the SMS table, as well.