Starting with API 23 and above, you need to add the correct permission to the manifest,
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
Then you can get information about the user, like,
String[] columnNames = new String[] {ContactsContract.Profile.DISPLAY_NAME, ContactsContract.Profile.PHOTO_ID}; Cursor c = activity.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, columnNames, null, null, null); int count = c.getCount(); boolean b = c.moveToFirst(); int position = c.getPosition(); if (count == 1 && position == 0) { for (int j = 0; j < count; j++) { String name = c.getString(c.getColumnIndex(ContactsContract.Profile.DISPLAY_NAME)); String photoID = c.getString(c.getColumnIndex(ContactsContract.Profile.PHOTO_ID)); Log.i("MainActivity", "name: " + name); Log.i("MainActivity", "photoID: "+ photoID); } } c.close()
Sazzad hissain khan
source share