Handle case where Uri from inserting SMS is null

This commit is contained in:
Moez Bhatti
2018-07-10 21:59:41 -04:00
parent 98856e7189
commit 44b90ef135
@@ -397,10 +397,12 @@ class MessageRepositoryImpl @Inject constructor(
put(Telephony.Sms.DATE_SENT, sentTime)
put(Telephony.Sms.SUBSCRIPTION_ID, subId)
}
val uri = context.contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values)
// Update the contentId after the message has been inserted to the content provider
realm.executeTransaction { managedMessage?.contentId = uri.lastPathSegment.toLong() }
context.contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values)?.let { uri ->
// Update the contentId after the message has been inserted to the content provider
realm.executeTransaction { managedMessage?.contentId = uri.lastPathSegment.toLong() }
}
realm.close()
return message