Prevent crash if exception occurs in native contact editor
This commit is contained in:
parent
84f0aceb61
commit
2748a34c25
1 changed files with 17 additions and 13 deletions
|
@ -50,19 +50,23 @@ class NativeContactEditor(val contact: NativeContact) {
|
||||||
val uri = result.uri
|
val uri = result.uri
|
||||||
Log.i("[Native Contact Editor] Contact creation result is $uri")
|
Log.i("[Native Contact Editor] Contact creation result is $uri")
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
val cursor = contentResolver.query(
|
try {
|
||||||
uri,
|
val cursor = contentResolver.query(
|
||||||
arrayOf(RawContacts.CONTACT_ID),
|
uri,
|
||||||
null,
|
arrayOf(RawContacts.CONTACT_ID),
|
||||||
null,
|
null,
|
||||||
null
|
null,
|
||||||
)
|
null
|
||||||
if (cursor != null) {
|
)
|
||||||
cursor.moveToNext()
|
if (cursor != null) {
|
||||||
val contactId: Long = cursor.getLong(0)
|
cursor.moveToNext()
|
||||||
Log.i("[Native Contact Editor] New contact id is $contactId")
|
val contactId: Long = cursor.getLong(0)
|
||||||
cursor.close()
|
Log.i("[Native Contact Editor] New contact id is $contactId")
|
||||||
return contactId
|
cursor.close()
|
||||||
|
return contactId
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("[Native Contact Editor] Failed to get cursor: $e")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue