package com.jiahaoliuliu.akami;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.Telephony;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.TextView;

import com.jiahaoliuliu.akami.model.Sms;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    // Projection. The fields of the sms to be returned
    private static final String[] sProjection = {
        Sms.COLUMN_ID,
        Sms.COLUMN_THREAD_ID,
        Sms.COLUMN_ADDRESS,
        Sms.COLUMN_DATE,
        Sms.COLUMN_DATE_SENT,
        Sms.COLUMN_BODY,
        Sms.COLUMN_TYPE
    };

    private Context mContext;

    // Views
    private TextView mMessagesTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.mContext = this;

        // Link the views
        mMessagesTextView = (TextView) findViewById(R.id.messages);

        // read messages
        readAllMessages();
    }

    private void readAllMessages() {
        List<Sms> smssList = new ArrayList<Sms>();
        Sms sms;
        Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), sProjection, null, null, null);
        if (cursor.moveToFirst()) {
            do {
                sms = new Sms();
                sms.set_id(cursor.getString(cursor.getColumnIndexOrThrow(Sms.COLUMN_ID)));
                sms.setThreadId(cursor.getString(cursor.getColumnIndexOrThrow(Sms.COLUMN_THREAD_ID)));
                sms.setAddress(cursor.getString(cursor.getColumnIndexOrThrow(Sms.COLUMN_ADDRESS)));
                sms.setDate((cursor.getString(cursor.getColumnIndexOrThrow(Sms.COLUMN_DATE))));
                sms.setDateSent((cursor.getString(cursor.getColumnIndexOrThrow(Sms.COLUMN_DATE_SENT))));
                sms.setBody((cursor.getString(cursor.getColumnIndexOrThrow(Sms.COLUMN_BODY))));

                if (cursor.getString(cursor.getColumnIndexOrThrow(Sms.COLUMN_TYPE)).contains("1")){
                    sms.setType("inbox");
                } else {
                    sms.setType("sent---------------------------");
                    break;
                }

                Log.v(TAG, "SMS read " + sms);
                smssList.add(sms);
            } while (cursor.moveToNext());

            mMessagesTextView.setText(smssList.toString());
        } else {
            Log.v(TAG, "The user does not have any sms");
            mMessagesTextView.setText("The user does not have any sms");
        }
    }

}

@@ -527,16 +527,76 @@
 tivity%22;
+%0A    private static final String ADDRESS_ADCB = %22ADCBAlert%22;
 %0A%0A    //
@@ -858,38 +858,245 @@
 BODY
-,
 %0A    
-    Sms.COLUMN_TYPE%0A    
+%7D;%0A%0A    // Selection query%0A    private static final String sSelectionClause = Sms.COLUMN_TYPE + %22=? and %22 + Sms.COLUMN_ADDRESS + %22=?%22;%0A%0A    // Selection arguments%0A    private static final String%5B%5D sSelectionArgs = %7B%221%22, ADDRESS_ADCB
 %7D;%0A%0A
@@ -1732,26 +1732,48 @@
 ection, 
-null, null
+sSelectionClause, sSelectionArgs
 , null);
@@ -2455,289 +2455,8 @@
 );%0A%0A
-                if (cursor.getString(cursor.getColumnIndexOrThrow(Sms.COLUMN_TYPE)).contains(%221%22))%7B%0A                    sms.setType(%22inbox%22);%0A                %7D else %7B%0A                    sms.setType(%22sent---------------------------%22);%0A                    break;%0A                %7D%0A%0A
     

Set correctly the selection query. Removed unused type field