ContentResolver cr = this.getContentResolver();
Cursor cursor = cr.query(Uri.parse("content://sms/inbox"), null, null,null, null);
cursor.moveToFirst();
if (cursor.getCount() > 0) {
    for (int j = 0; j < cursor.getCount(); j++) {
        String text = cursor.getString(
        cursor.getColumnIndexOrThrow("body")).toString();
        Log.d("sms", text);
        cursor.moveToNext();
    }
} else
    Log.d("no", "not working");
}
I also givev permission <uses-permission android:name="android.permission.READ_SMS"/> in androidmanifest.xml file it shows no notworking
 
    