How do I read all SMSes from a particular sender to me? E.g. I want to scan a) the body, and b) the date/time of all SMSes that came from \'TM-MYAMEX\' to the phone.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inbox = (Button) findViewById(R.id.inbox);
list = (ListView) findViewById(R.id.list);
arlist = new ArrayList();
inbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri inboxUri = Uri.parse("content://sms/inbox");
String[] reqCols = {"_id", "body", "address"};
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(inboxUri, reqCols, "address='+919456'", null, null);
adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.msg_content_layout, cursor,
new String[]{"body", "address"}, new int[]{R.id.txt1, R.id.txt2});
list.setAdapter(adapter);
}
});
}
Here I have added the number +919456 as the value of the address field.
Apart from this you need to add the READ_SMS permission to manifest: