Skip to content

Instantly share code, notes, and snippets.

@r0adkll
Created June 3, 2015 16:56
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 r0adkll/6f56e3f3d26e6be64fb6 to your computer and use it in GitHub Desktop.
Save r0adkll/6f56e3f3d26e6be64fb6 to your computer and use it in GitHub Desktop.
Get a users name from their Contact card
String nickName;
try {
Cursor c = getActivity().getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
c.moveToFirst();
nickName = c.getString(c.getColumnIndex("display_name")).concat("'s Android");
c.close();
}catch (Exception e){
Timber.e("Unable to load user's contact information, reverting to default device name");
nickName = Build.MANUFACTURER + " - " + Build.PRODUCT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment