0

I am new to Android. I want to know how to search by word in SMS inbox within the application. Can anyone help me. Please give me the source code if you could.

Anh3Saigon
  • 199
  • 5

3 Answers3

1

** Use Content Resolver ("content://sms/inbox") to read SMS which are in inbox.**

   Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null,     null, null, null);    
   cursor.moveToFirst();

   do{
   String msgData = "";
   for(int idx=0;idx<cursor.getColumnCount();idx++)
   {
       msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
   }
   if(msgData.contains(yourWord))
       ;// do something

   }while(cursor.moveToNext());
koleanu
  • 495
  • 5
  • 20
0

This seems to have been answered several times already here and there for pointer for instance. Please do search for existing questions before creating new ones.

Community
  • 1
  • 1
Sephy
  • 50,022
  • 30
  • 123
  • 131
0

first you have to query the inbox content provider for sms

  Uri uriSMSURI = Uri.parse("content://sms/inbox");
  Cursor cur = getContentResolver().query(uriSMSURI,new String[] { "_id", "thread_id",      "address", "person", "date", "body" }, null, null,null);

Then search iterate and get sms body

      if(cur.getCount()>0) {
        while(cur.moveToNext()) {
            String smsBody = cur.getString(5);
            Log.v("body",smsBody);

            if(smsBody.contains("matching string")) {


            }

also refer this link

how can i read inbox in android mobile?

Community
  • 1
  • 1
Vishwanath.M
  • 6,235
  • 11
  • 42
  • 56