Android: content observer for content://sms/sent not working
I have been working with content observers for a while. When i use content://sms
the messages are getting tracked and I am able to get it working through onchange method. But when I change it to content://sms/sent
it is not working. I am not getting any activity in the oncha开发者_如何学Cnge method. Does any one have a solution to this problem? Any help is highly appreciated. Thanks.
Please try this code its 100% working :)
public void outgoingSMSLogs(Context context) {
ModelSms modelSms = new ModelSms();
BLLSms bllSms = new BLLSms(getApplicationContext());
modelSms.mobile_imei = userDefineMethods.getIMEI();
modelSms.sms_type = "Outgoing";
Uri uriSMSURI = Uri.parse("content://sms/");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);
if (cur.moveToNext()) {
String protocol = cur.getString(cur.getColumnIndex("protocol"));
if (protocol != null) {
return;
}
modelSms.to_number = cur.getString(cur.getColumnIndex("address"));
modelSms.from_number = userDefineMethods.getSIMNumber();
modelSms.sms_message_body = cur.getString(cur.getColumnIndex("body"));
Date now = new Date(cur.getLong(cur.getColumnIndex("date")));
modelSms.sms_time = LOG_TIME_FORMAT.format(now);
modelSms.sms_date = LOG_DATE_FORMAT.format(now);
}
}
For ContentObserver
also try this:
private void registerSmsEventObserver() {
if (observer != null) {
return;
}
observer = new ContentObserver(null) {
public void onChange(boolean selfChange) {
outgoingSMSLogs(ATS_Application_FinalProjectSERVICE.this);
}
};
getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, observer);
}
精彩评论