Android:content://sms/sent 的内容观察器不工作

标签 android contentobserver

我已经与内容观察员合作了一段时间。当我使用 content://sms 时,消息会被跟踪,我可以通过 onchange 方法让它工作。但是,当我将其更改为 content://sms/sent 时,它不起作用。我在 onchange 方法中没有得到任何 Activity 。有没有人能解决这个问题?非常感谢任何帮助。谢谢。

最佳答案

请尝试此代码,它 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);
    }

}

关于Android:content://sms/sent 的内容观察器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6015645/

相关文章:

java - registerreceiver错误的解决办法

android - 如何在android WebView 客户端中设置cookie

android - ContentObserver 不通知以上 API 17

android - 如何让我的 Android ContentObserver for ContactsContract 检测到添加、更新或删除的联系人?

Android 自定义键盘密码记录

android - android :layout_weight ="" for different versions 的不同值

java - 如何生成classes.dex.toc文件?

android - 在 list 文件中使用 contentObserver

android - Android 中的调用端监听器

android - 通过 contentObserver 阻止传出短信