Search code examples
javaandroidcontactsandroid-contacts

What's the alternative of "ContactsContract.Contacts.LAST_TIME_CONTACTED"?


What should I use instead of ContactsContract.Contacts.LAST_TIME_CONTACTED? According to documentation, LAST_TIME_CONTACTED variable was deprecated. Even it was written in ContactsContract.class

/** @deprecated */
@Deprecated
String LAST_TIME_CONTACTED = "last_time_contacted";

Since it was deprecated then there must be another alternative. But why there's no alternative? Or why the documentation didn't link any alternative?

This constant was deprecated in API level 29.
Contacts affinity information is no longer supported as of Android version Build.VERSION_CODES.Q. This column always contains 0.

In Android Q or higher version, there's no alternative variable either?


Solution

  • There's no alternative - and it's intentional.

    Google no longer wants developers with Contacts permission to be able to get access to data related to communication between the user and their contacts.

    If you app is eligible to get the CALL_LOG or SMS permissions you can figure out the last contacted timestamp based on the call log / messaging history. But these permissions are not allowed in Google Play unless your app is of a very specific use-case documented here.