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!
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);
In Sms tables, Dates are stored as INTEGER in milliseconds. so, use
millis = cur.getLong(cur.getColumnIndexOrThrow("date"))
on Cursor.
Then, use
DateFormat.format("EEEE, MMMM dd, yyyy h:mm:ss aa", new Date(millis))
to get a nice readable string.
/**
* Read messages of respective phone number from msg
*
* @param activity
* @param ph_number
* @return
*/
public static void getMessageDetails(Activity activity, String ph_number) {
String forDelete_thread_id = "";
String forDelete_id = "";
String address = ph_number;
Uri allMsg = Uri.parse("content://sms/");
Cursor managedCursor = activity.getContentResolver().query(
allMsg,
new String[] { "_id", "thread_id", "address", "date", "body",
"type" }, "address=?", new String[] { address }, null);
while (managedCursor.moveToNext()) {
String msg_id = managedCursor.getString(0);
String thread_id = managedCursor.getString(1);
String address_b = managedCursor.getString(2);
String date = managedCursor.getString(3);
String msg_body = managedCursor.getString(4);
String type = managedCursor.getString(5);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With