How to access sms time which I have received in inbox?

Deepanker Chaudhary picture Deepanker Chaudhary · Oct 30, 2012 · Viewed 9.9k times · Source

I am able to read message from the inbox from this:--

 Uri uriSMSURI = Uri.parse("content://sms/inbox");

 Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);

i access date from this:-

   date = cur.getString(cur.getColumnIndexOrThrow("date"));

But now problem is that it gives current time not Message Time from inbox. Sorry for Bad editing & any idea will be appreciated. Thanks in Advance!

Answer

Sunil Mishra picture Sunil Mishra · Oct 30, 2012

Use this code:

ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query( Uri.parse( "content://sms/inbox" ), null, null, null, null);
cursor.moveToFirst();
String date =  cursor.getString(cursor.getColumnIndex("date"));
Long timestamp = Long.parseLong(date);    
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp);
Date finaldate = calendar.getTime();
String smsDate = finaldate.toString();
Log.d(Home.class.getName(), smsDate);