http://stackoverflow.com/questions/15326922/contentobserver-or-broadcastreceiver-for-incoming-sms
http://www.oschina.net/question/98375_128692
http://random-stuff-mine.blogspot.com/2013/07/monitoring-sent-received-sms-android.html
http://blog.csdn.net/matrix_laboratory/article/details/40350205
public static final String SMS_URI = "content://sms/";
public static final String SMS_INBOX_URI = "content://sms";
ContentResolver resolver = getContentResolver();
resolver.registerContentObserver(Uri.parse(SMS_URI), true,smsContentObserver);
private ContentObserver smsContentObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
super.onChange(true);
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(
Uri.parse(SMS_INBOX_URI),
new String[] { "_id", "address", "thread_id", "date",
"protocol", "type", "body", "read" },
" read=?", new String[] {"0"},
"date desc");
while(cursor.moveToNext()){
String address = cursor.getString(cursor.getColumnIndex("address"));
String body = cursor.getString(cursor.getColumnIndex("body"));
String id = cursor.getString(cursor.getColumnIndex("_id"));
//resolver.delete(Uri.parse("content://sms/"+id), null, null);
Toast.makeText(getApplicationContext(), address + "," + body, Toast.LENGTH_LONG).show();
Log.d("ContentObserver---", address + ":::::" + body);
break;
}
}
};
// MIUI ROM checkimport java.io.IOException;public final class MIUIUtils {private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";public static boolean isMIUI() {try {final BuildProperties prop = BuildProperties.newInstance();return prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null|| prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null|| prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null;} catch (final IOException e) {return false;}}}
Prior to KitKat (i.e. on your ROM) Tasker uses the ContentObserver content://mms-sms (need to pick up MMS too).
Perhaps the provider name difference accounts for the problem.
I have test ContentObserver for "content://mms-sms/conversations/", too. It's OK on my phone(MIUI 4.12.5, Android 4.1.2). Some code lines in my test project are taken from tutorial here.