Prevent crash if exception occurs in native contact editor

This commit is contained in:
Sylvain Berfini 2022-02-24 10:34:30 +01:00
parent 84f0aceb61
commit 2748a34c25

View file

@ -50,19 +50,23 @@ class NativeContactEditor(val contact: NativeContact) {
val uri = result.uri
Log.i("[Native Contact Editor] Contact creation result is $uri")
if (uri != null) {
val cursor = contentResolver.query(
uri,
arrayOf(RawContacts.CONTACT_ID),
null,
null,
null
)
if (cursor != null) {
cursor.moveToNext()
val contactId: Long = cursor.getLong(0)
Log.i("[Native Contact Editor] New contact id is $contactId")
cursor.close()
return contactId
try {
val cursor = contentResolver.query(
uri,
arrayOf(RawContacts.CONTACT_ID),
null,
null,
null
)
if (cursor != null) {
cursor.moveToNext()
val contactId: Long = cursor.getLong(0)
Log.i("[Native Contact Editor] New contact id is $contactId")
cursor.close()
return contactId
}
} catch (e: Exception) {
Log.e("[Native Contact Editor] Failed to get cursor: $e")
}
}
}