-1

I want specific sms to be displayed in my listview in application. Now using below code all sms are displayed in listview.

MainActivity.java 
{
    ListView lViewSMS = (ListView) findViewById(R.id.listViewSMS); 
    if(fetchInbox()!=null)
    { 
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, fetchInbox());
        lViewSMS.setAdapter(adapter);
    }
} 
public ArrayList fetchInbox()
{
    ArrayList sms = new ArrayList(); 
    Uri uriSms = Uri.parse("content://sms/inbox");        
    Cursor cursor = getContentResolver().query(uriSms, new String[]{"_id", "address", "date", "body"},null,null,null);
    cursor.moveToFirst();        
    while  (cursor.moveToNext())
    {
        String address = cursor.getString(1);
        String body = cursor.getString(3); 
        System.out.println("======> Mobile number => "+address);
        System.out.println("=====> SMS Text => "+body); 
        sms.add("Address="+address+"\n"+"SMS="+body);
    }
return sms;
}
MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
andi
  • 13
  • 2

1 Answers1

-1

You Can filter the Sms from cursor. See the this example they filter the Sms by phone number. similarly you can filter by sms body etc.

Community
  • 1
  • 1
MathanG
  • 1,195
  • 10
  • 22