Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ContentObserver:如何只获取新的更新数据?_Android_Contentobserver - Fatal编程技术网

Android ContentObserver:如何只获取新的更新数据?

Android ContentObserver:如何只获取新的更新数据?,android,contentobserver,Android,Contentobserver,我在我的应用程序中注册SMS ContentObserver。我想用MessageID更新我的ArrayList onChange。这是我的观察员代码 public class SmsObserver extends ContentObserver { private Context mContext; private String contactId = "", contactName = ""; private String smsBodyStr = "", ph

我在我的应用程序中注册SMS ContentObserver。我想用MessageID更新我的ArrayList onChange。这是我的观察员代码

public class SmsObserver extends ContentObserver {

    private Context mContext;

    private String contactId = "", contactName = "";
    private String smsBodyStr = "", phoneNoStr = "";
    private long smsDatTime = System.currentTimeMillis();

    static final Uri SMS_STATUS_URI = Uri.parse("content://sms");

    public SmsObserver(Handler handler, Context ctx) {
        super(handler);
        mContext = ctx;
    }     

    public boolean deliverSelfNotifications() {
        return true;
    }

    public void onChange(boolean selfChange) {
        try{
            Cursor sms_sent_cursor = mContext.getContentResolver().query(SMS_STATUS_URI, null, null, null, null);
            if (sms_sent_cursor != null) {
                if (sms_sent_cursor.moveToFirst()) {
                    String protocol = sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("protocol"));
                    if(protocol == null){
                        int type = sms_sent_cursor.getInt(sms_sent_cursor.getColumnIndex        ("type"));                       
                        if(type == 2){
                            smsBodyStr = sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("body")).trim();
                            phoneNoStr = sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("address")).trim();
                            smsDatTime = sms_sent_cursor.getLong(sms_sent_cursor.getColumnIndex("date"));
                        }
                    }
                }
            } else {
                Log.e("Info","Send Cursor is Empty");
            }
        } catch(Exception sggh) {
            Log.e("Error", "Error on onChange : "+sggh.toString());
        }
        super.onChange(selfChange);
    }
}

但是,我正在发送两条消息。第一个是电话关了。第二个是电话开着。第一个更新是后者。第二次更新是我第一次发送,手机打开。有了这个观察者,我只能访问最新的帖子。仅显示最新数据。如何获取新的更新数据?

请将您的问题说得更清楚。很抱歉,这很容易混淆,没有问题。我更改了sms数据库中的一条消息数据。我在sms数据库中添加了observer。但我使用“moveToNext()”,只看到最后一条消息。。显示不是上次更新,上次插入。。。我想查看上次更新的数据。。。