Reputation: 678
We have an Android app where we are trying to read all the messages available in the phone. We are using READ_SMS permission but we are not able to read service messages in this way. By service mesaage I mean the messages obtained from different companies. For example I have messages in my phone from Amazon and Paytm but I am not able to load these while loading messages. I don't understand the issue. Is there any default filter that android is applying when the SMS get loaded or is there any issue with the code?
I use the following code to load all SMS:
private ArrayList load_sms(){
ContentResolver contentResolver = getContentResolver();
ArrayList<String> smsList = new ArrayList<>();
Cursor smsInboxCursor =
contentResolver.query(Uri.parse("content://sms/inbox"),
null,null,null,null);
int indexBody = smsInboxCursor.getColumnIndex("body");
int indexAddress = smsInboxCursor.getColumnIndex("address");
if(indexBody < 0 || !smsInboxCursor.moveToFirst())
return null;
do{
smsList.add("SMS From: " +
smsInboxCursor.getString(indexAddress) + " \nMessage: "
+ smsInboxCursor.getString(indexBody));
}while (smsInboxCursor.moveToNext());
return smsList;
}
Upvotes: 1
Views: 1291
Reputation: 678
So, the solution was quite vague. I have a MI phone and found that MI blocks service messages. To view those SMS' I had to give the permission manually from settings as given in this link: Can't read service messages in Redmi Note 3
When I ran my app on some other phone like in Samsung, I was able to view all the messages.
Upvotes: 1