0

I'm using a bit of code to get the ID of the current user's profile:

val cursor = contentResolver.query(
    ContactsContract.Profile.CONTENT_URI,
    arrayOf(ContactsContract.Profile._ID),
    null,
    null,
    null
)

cursor.moveToFirst()

val id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Profile._ID))
cursor.close()

On my Galaxy S7 device running Android 8.0.0 (API level 26) this works properly, but on the Nexus 5X emulator also running 8.0.0, I get CursorIndexOutOfBoundsException, implying that there is no user profile present.

My understanding was that since API 14 this method was guaranteed to return the user's profile, which exists by default. Why then is there no result?

4

0 回答 0