0

I register SMS ContentObserver in my app. I want to update my ArrayList onChange with MessageID. This is my ObServer code..

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

But, I am sending two messages. The first one is the phone closed. The second is the phone open. The first update is the latter. The second update is the first I sent the phone opens. With this ObServer I can access only the most recent post. Showing only the most recent data. How can I get the new updated data?

  • 1
    please make your question more clear..sorry to say but it was confusing – Aditya Jul 24 '13 at 20:12
  • No problem. I changed the one message data in sms database. And I add observer in sms database. But I using "moveToNext()", I only reach last message.. Show not last updated, last insert... I want to reach last updated data... – Abdulkadir NURKALEM Jul 26 '13 at 20:39

0 Answers0