Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 1.43 KB  |  hits: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android: content observer for content://sms/sent not working
  2. for content observer try this also ....
  3.  
  4. private void registerSmsEventObserver() {
  5.         if (observer != null) {
  6.             return;
  7.         }
  8.         observer = new ContentObserver(null) {
  9.             public void onChange(boolean selfChange) {
  10.                 outgoingSMSLogs(ATS_Application_FinalProjectSERVICE.this);
  11.             }
  12.         };
  13.         getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, observer);
  14.     }
  15.        
  16. public void outgoingSMSLogs(Context context) {
  17.     ModelSms modelSms = new ModelSms();
  18.     BLLSms bllSms = new BLLSms(getApplicationContext());
  19.  
  20.     modelSms.mobile_imei = userDefineMethods.getIMEI();
  21.     modelSms.sms_type = "Outgoing";
  22.  
  23.     Uri uriSMSURI = Uri.parse("content://sms/");
  24.     Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);
  25.     if (cur.moveToNext()) {
  26.         String protocol = cur.getString(cur.getColumnIndex("protocol"));
  27.         if (protocol != null) {
  28.             return;
  29.         }
  30.         modelSms.to_number = cur.getString(cur.getColumnIndex("address"));
  31.         modelSms.from_number = userDefineMethods.getSIMNumber();
  32.         modelSms.sms_message_body = cur.getString(cur.getColumnIndex("body"));
  33.  
  34.         Date now = new Date(cur.getLong(cur.getColumnIndex("date")));
  35.         modelSms.sms_time = LOG_TIME_FORMAT.format(now);
  36.         modelSms.sms_date = LOG_DATE_FORMAT.format(now);
  37.     }
  38.  
  39. }