I am developing an app in which i want to count the last date total inbox SMS
. i am using this code
TextView view = new TextView(this);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
long now = System.currentTimeMillis();
long last24 = now - 24*60*60*1000;//24h in millis
String[] selectionArgs = new String[]{Long.toString(last24)};
String selection = "date" + ">?";
String[] projection = new String[]{"date"};
Cursor cur = getContentResolver().query(uriSMSURI, projection, selection, selectionArgs,null);
String sms = String.valueOf(cur.getCount());
view.setText("Total incoming today SMS "+sms);
setContentView(view);
I am able to count the last 24 hours inbox sms, but I need to count last date inbox sms. like today Date is 28/02/13
but i want to count total inbox sms of Date 27/02/13
.
please help me i am new learner thanks in advance.
try to set selection as date between date('now', '-1 day') and date('now')
, remove selectionArgs
Update:
Cursor cur = getContentResolver().query(uriSMSURI, projection, "datetime(date/1000, 'unixepoch') between date('now', '-1 day') and date('now')", null, null);