2011-05-16 87 views
5

我一直在與內容觀察員合作一段時間。當我使用content://sms消息正在跟蹤,我可以通過onchange方法得到它的工作。但是當我將其更改爲content://sms/sent時,它不起作用。我在onchange方法中沒有得到任何活動。有沒有人可以解決這個問題?任何幫助,高度讚賞。謝謝。Android:內容觀察者的內容://短信/發送不工作

回答

0

請試試這個代碼的100%的工作:)

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); 
    } 

} 
0

對於ContentObserver也試試這個:

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); 
    }