6

我和内容观察者合作了一段时间。当我使用content://sms消息被跟踪时,我可以通过 onchange 方法让它工作。但是当我改变它时 content://sms/sent它不起作用。我在 onchange 方法中没有任何活动。有没有人可以解决这个问题?非常感谢任何帮助。谢谢。

4

2 回答 2

0

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);
    }
于 2012-02-28T11:48:20.447 回答
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);
    }

}
于 2012-02-28T11:43:14.940 回答