diff --git a/app/build.gradle b/app/build.gradle index 1ef38dc6..db58dfb2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -70,6 +70,7 @@ dependencies { implementation "me.leolin:ShortcutBadger:1.1.22" implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3' + implementation 'androidx.lifecycle:lifecycle-process:2.5.1' kapt "androidx.room:room-compiler:2.4.3" implementation "androidx.room:room-runtime:2.4.3" diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsStatusSentReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsStatusSentReceiver.kt index 32db10ea..3b324d63 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsStatusSentReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/SmsStatusSentReceiver.kt @@ -7,6 +7,8 @@ import android.net.Uri import android.os.Handler import android.os.Looper import android.provider.Telephony +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.ProcessLifecycleOwner import com.klinker.android.send_message.SentReceiver import com.simplemobiletools.commons.extensions.getMyContactsCursor import com.simplemobiletools.commons.helpers.ensureBackgroundThread @@ -20,12 +22,10 @@ class SmsStatusSentReceiver : SentReceiver() { val uri = Uri.parse(intent.getStringExtra("message_uri")) val messageId = uri?.lastPathSegment?.toLong() ?: 0L ensureBackgroundThread { - if (intent.extras!!.containsKey("errorCode")) { - showSendingFailedNotification(context, messageId) - } val type = if (receiverResultCode == Activity.RESULT_OK) { Telephony.Sms.MESSAGE_TYPE_SENT } else { + showSendingFailedNotification(context, messageId) Telephony.Sms.MESSAGE_TYPE_FAILED } @@ -46,6 +46,9 @@ class SmsStatusSentReceiver : SentReceiver() { private fun showSendingFailedNotification(context: Context, messageId: Long) { Handler(Looper.getMainLooper()).post { + if (ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) { + return@post + } val privateCursor = context.getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true) ensureBackgroundThread { val address = context.getMessageRecipientAddress(messageId)