For Android, is there a way to determine how many text messages have been sent to a contact?

StackOverflow https://stackoverflow.com/questions/4632222

  •  08-10-2019
  •  | 
  •  

Question

I'm reading contact data from ContractContacts, and can lookup TIMES_CONTACTED (which is useful to me), but this field only applies to calls to that contact. I'm also interested in the number of times a contact has been contacted via SMS or email.

Does anyone know if this information is available? I've been searching but haven't come across anything.

Was it helpful?

Solution

For SMS, you'll want to access the inbox located at content://sms/inbox directly and perform a database query to count the number of rows corresponding to the matching contact.

Something like:

String personAddress = addressFromContact();
Uri smsUri = new Uri("content://sms");
if (smsUri != null) {
  Cursor smsCursor = getContentResolver().query(smsUri, null, "address=?", new String[] {personAddress}, null);
  int smsCount = smsCursor.getCount();
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top