- differentiate between sent sms and delivered sms by updating the SmsStatusSentReceiver which updates the type to Telephony.Sms.MESSAGE_TYPE_SENT or Telephony.Sms.MESSAGE_TYPE_FAILED depending on the outcome. - rename ThreadSuccess to ThreadSent and add a boolean field for the delivery status - SmsStatusSentReceiver updates the status of the message to Telephony.Sms.STATUS_COMPLETE. - accommodate for the need to keep track of the status by adding Int field status to the Message class, - add appropriate database migrations (3 to 4) for the new status field. - add status to the query for sms in extension function Context.getMessages and Context.getMMS - add extension function Context.updateMessageStatus to update the status of a message in the database
37 lines
1.5 KiB
Kotlin
37 lines
1.5 KiB
Kotlin
package com.simplemobiletools.smsmessenger.receivers
|
|
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import android.net.Uri
|
|
import android.os.Handler
|
|
import android.os.Looper
|
|
import android.provider.Telephony
|
|
import com.klinker.android.send_message.DeliveredReceiver
|
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|
import com.simplemobiletools.smsmessenger.extensions.messagesDB
|
|
import com.simplemobiletools.smsmessenger.extensions.updateMessageStatus
|
|
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
|
|
|
class SmsStatusDeliveredReceiver : DeliveredReceiver() {
|
|
|
|
override fun onMessageStatusUpdated(context: Context, intent: Intent, receiverResultCode: Int) {
|
|
if (intent.extras?.containsKey("message_uri") == true) {
|
|
val uri = Uri.parse(intent.getStringExtra("message_uri"))
|
|
val messageId = uri?.lastPathSegment?.toLong() ?: 0L
|
|
ensureBackgroundThread {
|
|
val status = Telephony.Sms.STATUS_COMPLETE
|
|
context.updateMessageStatus(messageId, status)
|
|
val updated = context.messagesDB.updateStatus(messageId, status)
|
|
if (updated == 0) {
|
|
Handler(Looper.getMainLooper()).postDelayed({
|
|
ensureBackgroundThread {
|
|
context.messagesDB.updateStatus(messageId, status)
|
|
}
|
|
}, 2000)
|
|
}
|
|
|
|
refreshMessages()
|
|
}
|
|
}
|
|
}
|
|
}
|