-4

I need to create an android application to read all SMS come to my phone. It should be just like the, new feture in facebook messenger, to show all sms in my phone inbox. Could help me by providing the source code.

Deepu
  • 19
  • 1
  • 4

1 Answers1

2

You can fetch all inbox sms using Uri. Use this code for getting all inbox sms:

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("Text: "+body);
    }

Also add READ_SMS permission inside the AndroidManifest.xml file:

<uses-permission android:name="android.permission.READ_SMS"></uses-permission>

Later show these sms in a ListView.

Pial Kanti
  • 1,550
  • 2
  • 13
  • 26