Created
June 3, 2015 16:56
-
-
Save r0adkll/6f56e3f3d26e6be64fb6 to your computer and use it in GitHub Desktop.
Get a users name from their Contact card
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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