Reputation: 1704
I am able to read SMS in Android from this:-
phonesms = new ArrayList<String>();
ContentResolver cr = getContentResolver();
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
startManagingCursor(cur);
if (cur.moveToFirst()) {
for (int i = 0; i < cur.getCount(); i++) {
try {
String smsbody = cur.getString(cur.getColumnIndexOrThrow("body")).toString();
phonesms.add(smsbody);
} catch (Exception e) {
}
Now Problem is that I want to access Unread SMS & send Unread SMS automatically Through Email in a time period.
I can send sms on email from two methods:- 1. Through Intent 2.Java Mail Api
But How to send unread sms automatically via Email within a fixed Time Period.
Upvotes: 0
Views: 2451
Reputation: 4715
YOu can can use cur.getString(cur.getColumnIndexOrThrow("status") to determine whether it is read or not. Or you can include them in the query itself to filter out only messages which are unread.
while (cur.moveToNext()) {
String address = cur.getString(cur.getColumnIndex("address"));
String body = cur.getString(cur.getColumnIndexOrThrow("body"));
int status = cur.getString(cur.getColumnIndexOrThrow("status"));
if(status == SmsManager.STATUS_ON_ICC_UNREAD ) {
//do whatever you want
}
}
Upvotes: 0
Reputation: 22064
To get unread sms:
Cursor cur = getContentResolver().query(uriSMSURI, null, "read = 0", null, null);
Upvotes: 1