How to get the SMS date from messenger?
Clash Royale CLAN TAG#URR8PPP
How to get the SMS date from messenger?
Android default messenger sort SMS in several groups using received time(picture).
I am trying to show sms inbox in custom listview like default messenger using cursor:
// Create Inbox box URI
Uri inboxURI = Uri.parse( "content://sms/inbox" );
// List required columns
String reqCols = new String"_id", "address", "body", "date";
// Get Content Resolver object, which will deal with Content
// Provider
ContentResolver contentResolver = getContentResolver();
// Fetch Inbox SMS Message from Built-in Content Provider
Cursor cursor = contentResolver.query( inboxURI, reqCols, null, null,
null );
sms = new ArrayList<>();
String date = "";
cursor.moveToLast();
while (cursor.moveToPrevious() || cursor.isLast()) {
//to get phone number
address = cursor.getString( cursor.getColumnIndex( "address" ) );
//to get massage
body = cursor.getString( cursor.getColumnIndexOrThrow( "body" ) );
//to get date of sms
date = cursor.getString( cursor.getColumnIndexOrThrow( "date" ) );
Long timestamp = Long.parseLong( date );
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis( timestamp );
Date finalDate = calendar.getTime();
smsDate = finalDate.toString();
but it is not working like that.It's like "Sun Aug 12 07:13:13 .....". I want to show time same as default messenger. What is the solution?
1 Answer
1
In Sms tables, Dates are stored as INTEGER in milliseconds. so, use
long sms_time= cur.getLong(cur.getColumnIndexOrThrow("date")) on Cursor.
This is the time in milli on which the SMS was recieved. Now Get The Current Time In Milli Seconds.
long now = System.currentTimeMillis();//get Current Time
now Calculate M=Difference In Minutes:
long minutes=(now - sms_time)/(1000*60);
Source: https://stackoverflow.com/a/13138710/3155082
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
@ Jawad Zeb thank you.
– taha amiri
Aug 12 at 8:47