diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4c0108ca..814fde4a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -163,6 +163,15 @@
+
+
+
+
+
+
): Long {
fun Context.showReceivedMessageNotification(address: String, body: String, threadID: Int, bitmap: Bitmap?) {
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
- val channelId = "simple_sms_messenger"
if (isOreoPlus()) {
val audioAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
@@ -562,7 +561,7 @@ fun Context.showReceivedMessageNotification(address: String, body: String, threa
val name = getString(R.string.channel_received_sms)
val importance = NotificationManager.IMPORTANCE_HIGH
- NotificationChannel(channelId, name, importance).apply {
+ NotificationChannel(NOTIFICATION_CHANNEL, name, importance).apply {
setBypassDnd(false)
enableLights(true)
setSound(soundUri, audioAttributes)
@@ -583,12 +582,32 @@ fun Context.showReceivedMessageNotification(address: String, body: String, threa
action = MARK_AS_READ
putExtra(THREAD_ID, threadID)
}
+
val markAsReadPendingIntent = PendingIntent.getBroadcast(this, 0, markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT)
+ var replyAction: NotificationCompat.Action? = null
+
+ if (isNougatPlus()) {
+ val replyLabel = getString(R.string.reply)
+ val remoteInput = RemoteInput.Builder(REPLY)
+ .setLabel(replyLabel)
+ .build()
+
+ val replyIntent = Intent(this, DirectReplyReceiver::class.java).apply {
+ putExtra(THREAD_ID, threadID)
+ putExtra(THREAD_NUMBER, address)
+ }
+
+ val replyPendingIntent = PendingIntent.getBroadcast(applicationContext, threadID, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT)
+ replyAction = NotificationCompat.Action.Builder(R.drawable.ic_send_vector, replyLabel, replyPendingIntent)
+ .addRemoteInput(remoteInput)
+ .build()
+ }
val largeIcon = bitmap ?: SimpleContactsHelper(this).getContactLetterIcon(sender)
- val builder = NotificationCompat.Builder(this, channelId)
+ val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL)
.setContentTitle(sender)
.setContentText(body)
+ .setColor(config.primaryColor)
.setSmallIcon(R.drawable.ic_messenger)
.setLargeIcon(largeIcon)
.setStyle(NotificationCompat.BigTextStyle().setSummaryText(summaryText).bigText(body))
@@ -599,7 +618,11 @@ fun Context.showReceivedMessageNotification(address: String, body: String, threa
.setAutoCancel(true)
.setSound(soundUri, AudioManager.STREAM_NOTIFICATION)
.addAction(R.drawable.ic_check_vector, getString(R.string.mark_as_read), markAsReadPendingIntent)
- .setChannelId(channelId)
+ .setChannelId(NOTIFICATION_CHANNEL)
+
+ if (replyAction != null) {
+ builder.addAction(replyAction)
+ }
notificationManager.notify(threadID, builder.build())
}
diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt
index d3cf7cd1..e6b48d46 100644
--- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt
@@ -10,9 +10,11 @@ const val THREAD_NUMBER = "thread_number"
const val THREAD_ATTACHMENT_URI = "thread_attachment_uri"
const val THREAD_ATTACHMENT_URIS = "thread_attachment_uris"
const val USE_SIM_ID_PREFIX = "use_sim_id_"
+const val NOTIFICATION_CHANNEL = "simple_sms_messenger"
private const val PATH = "com.simplemobiletools.smsmessenger.action."
const val MARK_AS_READ = PATH + "mark_as_read"
+const val REPLY = PATH + "reply"
// view types for the thread list view
const val THREAD_DATE_TIME = 1
diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/DirectReplyReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/DirectReplyReceiver.kt
new file mode 100644
index 00000000..be837509
--- /dev/null
+++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/receivers/DirectReplyReceiver.kt
@@ -0,0 +1,51 @@
+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
+
+class DirectReplyReceiver : BroadcastReceiver() {
+ override fun onReceive(context: Context, intent: Intent) {
+ val address = intent.getStringExtra(THREAD_NUMBER)
+ val threadId = intent.getIntExtra(THREAD_ID, 0)
+ val msg = RemoteInput.getResultsFromIntent(intent).getCharSequence(REPLY).toString()
+
+ val settings = Settings()
+ settings.useSystemSending = true
+
+ val transaction = Transaction(context, settings)
+ val message = com.klinker.android.send_message.Message(msg, address)
+
+ try {
+ transaction.sendNewMessage(message, threadId.toLong())
+ } 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, repliedNotification)
+
+ ensureBackgroundThread {
+ context.markThreadMessagesRead(threadId)
+ context.conversationsDB.markRead(threadId.toLong())
+ }
+ }
+}