mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-01-01 02:57:27 +01:00
properly handle sending reply messages through the top notification
This commit is contained in:
parent
c73f1f2dfe
commit
6c9d25d16f
@ -3,17 +3,14 @@ package com.simplemobiletools.smsmessenger.receivers
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.RemoteInput
|
||||
import com.klinker.android.send_message.Settings
|
||||
import com.klinker.android.send_message.Transaction
|
||||
import com.simplemobiletools.commons.extensions.notificationManager
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.extensions.conversationsDB
|
||||
import com.simplemobiletools.smsmessenger.extensions.markThreadMessagesRead
|
||||
import com.simplemobiletools.smsmessenger.helpers.NOTIFICATION_CHANNEL
|
||||
import com.simplemobiletools.smsmessenger.helpers.REPLY
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER
|
||||
@ -26,22 +23,24 @@ class DirectReplyReceiver : BroadcastReceiver() {
|
||||
|
||||
val settings = Settings()
|
||||
settings.useSystemSending = true
|
||||
settings.deliveryReports = true
|
||||
|
||||
val transaction = Transaction(context, settings)
|
||||
val message = com.klinker.android.send_message.Message(msg, address)
|
||||
|
||||
try {
|
||||
val smsSentIntent = Intent(context, SmsStatusSentReceiver::class.java)
|
||||
val deliveredIntent = Intent(context, SmsStatusDeliveredReceiver::class.java)
|
||||
|
||||
transaction.setExplicitBroadcastForSentSms(smsSentIntent)
|
||||
transaction.setExplicitBroadcastForDeliveredSms(deliveredIntent)
|
||||
|
||||
transaction.sendNewMessage(message, threadId)
|
||||
} catch (e: Exception) {
|
||||
context.showErrorToast(e)
|
||||
}
|
||||
|
||||
val repliedNotification = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL)
|
||||
.setSmallIcon(R.drawable.ic_messenger)
|
||||
.setContentText(msg)
|
||||
.build()
|
||||
|
||||
context.notificationManager.notify(threadId.hashCode(), repliedNotification)
|
||||
context.notificationManager.cancel(threadId.hashCode())
|
||||
|
||||
ensureBackgroundThread {
|
||||
context.markThreadMessagesRead(threadId)
|
||||
|
@ -41,6 +41,7 @@ class SmsStatusSentReceiver : SentReceiver() {
|
||||
} else {
|
||||
Telephony.Sms.MESSAGE_TYPE_OUTBOX
|
||||
}
|
||||
|
||||
context.updateMessageType(messageId, type)
|
||||
context.messagesDB.updateType(messageId, type)
|
||||
refreshMessages()
|
||||
|
@ -6,6 +6,8 @@ import android.net.Uri
|
||||
import com.klinker.android.send_message.Settings
|
||||
import com.klinker.android.send_message.Transaction
|
||||
import com.simplemobiletools.smsmessenger.extensions.getThreadId
|
||||
import com.simplemobiletools.smsmessenger.receivers.SmsStatusDeliveredReceiver
|
||||
import com.simplemobiletools.smsmessenger.receivers.SmsStatusSentReceiver
|
||||
|
||||
class HeadlessSmsSendService : Service() {
|
||||
override fun onBind(intent: Intent?) = null
|
||||
@ -20,8 +22,17 @@ class HeadlessSmsSendService : Service() {
|
||||
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||
val settings = Settings()
|
||||
settings.useSystemSending = true
|
||||
settings.deliveryReports = true
|
||||
|
||||
val transaction = Transaction(this, settings)
|
||||
val message = com.klinker.android.send_message.Message(text, number)
|
||||
|
||||
val smsSentIntent = Intent(this, SmsStatusSentReceiver::class.java)
|
||||
val deliveredIntent = Intent(this, SmsStatusDeliveredReceiver::class.java)
|
||||
|
||||
transaction.setExplicitBroadcastForSentSms(smsSentIntent)
|
||||
transaction.setExplicitBroadcastForDeliveredSms(deliveredIntent)
|
||||
|
||||
transaction.sendNewMessage(message, getThreadId(number))
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user