Reputation: 1715
I can get contact id and name from my contact list. But LAST_TIME_CONTACTED returns 0. How can I get LAST_TIME_CONTACTED correctly ?
My code:
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0)
{
while (cur.moveToNext())
{
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String last = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LAST_TIME_CONTACTED));
}
}
Upvotes: 1
Views: 668
Reputation: 4910
Like Ed Hinchliffe said, it seems to be an unreliable field. However, you might be able to store such a value yourself if that is acceptable for your use case.
If you use a BroadcastReceiver
and a PhoneStateListener
you might be able to pull it off.
You would simply need to use String.valueOf(currentDate.getTime());
and store the value somewhere.
Upvotes: 1
Reputation: 19098
By the looks of things this isn't properly implemented by all device manufacturers. As such it seems like an unreliable field to use unfortunately. Almost certainly the case if you're using a Samsung Galaxy device...
As a side note, I think it's stored as an integer so you might be better using getInt()
but I doubt very much that that's the problem.
Upvotes: 1