Skip to content

Instantly share code, notes, and snippets.

@hughes
Created March 2, 2014 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughes/9315684 to your computer and use it in GitHub Desktop.
Save hughes/9315684 to your computer and use it in GitHub Desktop.
private String makeMessageStr(HashMap<String, String> messageHash) {
String from_number = messageHash.get("from_number");
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(from_number));
Cursor people = getContentResolver().query(uri, new String[]{ContactsContract.PhoneLookup.DISPLAY_NAME}, null, null, null);
int indexName = people.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
String name = from_number;
if (people.getCount() > 0) {
people.moveToFirst();
do {
name = people.getString(indexName);
Log.v("VP", "Found name: " + name);
} while (people.moveToNext());
} else {
Log.v("VP", "No contacts found");
}
String message = name;
try {
Date date = ISO8601.toCalendar(messageHash.get("created_at")).getTime();
message += " - " + dateFormat.format(date);
} catch(ParseException e) {
Log.e("VP", "Datetime parse error", e);
}
Log.v("VP", message);
return message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment