3

I am working on an android app, where I need to save sender, SMS body, date and time of the incoming SMS. Right now I can be able to capture the message body and sender. But I cant able to get the date and time of SMS. Even I checked out some of the posts in stackoverflow but none of them capture date and time. So can anyone here please suggest or show me piece of code to capture date and time from incoming SMS? Thanks in advance

NOTE: I tried the following links

  1. How to analyze incoming SMS on Android?
  2. How would i track Incoming SMS in Android?
Community
  • 1
  • 1
CrazyCoder
  • 2,465
  • 8
  • 36
  • 57

1 Answers1

6

Does getTimestampMillis() not help?

To get the date & time values, do this:

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(smsMessage.getTimestampMillis());

int date = calendar.get(CALENDAR.DATE);
int hour = calendar.get(CALENDAR.HOUR_OF_DAY);
// etc...
Dheeraj Vepakomma
  • 26,870
  • 17
  • 81
  • 104