Get the date from SMS android… here is a solution to the problem.
Get the date from SMS android
Possible Duplicate:
Android – get date time from SMS timestamp in miliseconds
I’m using the following code to record a text message:
public void getColumnData(Cursor cur, Context context) {
ArrayList<String> exportBuffer = new ArrayList<String>();
try {
if (cur.moveToFirst()) {
String id;
String date;
String phoneNumber;
String body;
int idColumn = cur.getColumnIndex("_id");
int dateColumn = cur.getColumnIndex("date");
int numberColumn = cur.getColumnIndex("address");
int bodyColumn = cur.getColumnIndex("body");
do {
id = cur.getString(idColumn);
date = cur.getString(dateColumn);
body = cur.getString(bodyColumn);
phoneNumber = cur.getString(numberColumn);
String FormattedDate;
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd-MM-yyyy");
FormattedDate = sdf.format(date).toString();
exportBuffer.add(id + " ," + FormattedDate + " ," + body + " ,"
+ phoneNumber);
} while (cur.moveToNext());
}
WriteToFile(exportBuffer,context);
} catch (Exception e) {
int MessageDuration = Toast.LENGTH_SHORT;
CharSequence text = "An Error Occurred, Code:104";
Toast toast = Toast.makeText(context, text, MessageDuration);
toast.show();
}
}
Everything works fine except for the date string, I don’t know what format it is, which means I can’t format it to the correct date, here is an example of one of the dates:
1309817682651
Thanks in advance.