rely on klinkerapps library at sending SMS too, not just MMS
This commit is contained in:
parent
fce6ed2640
commit
cd26b96384
|
@ -36,7 +36,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.25.11'
|
||||
implementation 'com.simplemobiletools:commons:5.25.12'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'com.klinkerapps:android-smsmms:5.2.6'
|
||||
|
|
|
@ -142,7 +142,10 @@
|
|||
android:exported="true"
|
||||
android:taskAffinity="com.klinker.android.messaging.MMS_RECEIVED" />
|
||||
|
||||
<receiver android:name=".receivers.SmsSentReceiver" />
|
||||
<receiver
|
||||
android:name=".receivers.SmsSentReceiver"
|
||||
android:exported="true"
|
||||
android:taskAffinity="${applicationId}.SMS_SENT" />
|
||||
|
||||
<activity-alias
|
||||
android:name=".activities.SplashActivity.Red"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simplemobiletools.smsmessenger.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.drawable.Drawable
|
||||
|
@ -9,7 +8,6 @@ import android.media.MediaMetadataRetriever
|
|||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.Telephony
|
||||
import android.telephony.SmsManager
|
||||
import android.text.TextUtils
|
||||
import android.view.Gravity
|
||||
import android.view.Menu
|
||||
|
@ -38,9 +36,11 @@ import com.simplemobiletools.smsmessenger.R
|
|||
import com.simplemobiletools.smsmessenger.adapters.AutoCompleteTextViewAdapter
|
||||
import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
|
||||
import com.simplemobiletools.smsmessenger.extensions.*
|
||||
import com.simplemobiletools.smsmessenger.helpers.*
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_TEXT
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_TITLE
|
||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||
import com.simplemobiletools.smsmessenger.models.*
|
||||
import com.simplemobiletools.smsmessenger.receivers.SmsSentReceiver
|
||||
import kotlinx.android.synthetic.main.activity_thread.*
|
||||
import kotlinx.android.synthetic.main.item_attachment.view.*
|
||||
import kotlinx.android.synthetic.main.item_selected_contact.view.*
|
||||
|
@ -392,35 +392,27 @@ class ThreadActivity : SimpleActivity() {
|
|||
return
|
||||
}
|
||||
|
||||
participants.forEach {
|
||||
if (attachmentUris.isEmpty()) {
|
||||
val intent = Intent(this, SmsSentReceiver::class.java).apply {
|
||||
putExtra(MESSAGE_BODY, msg)
|
||||
putExtra(MESSAGE_ADDRESS, it.phoneNumber)
|
||||
}
|
||||
|
||||
val pendingIntent = PendingIntent.getBroadcast(this, threadId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val smsManager = SmsManager.getDefault()
|
||||
smsManager.sendTextMessage(it.phoneNumber, null, msg, pendingIntent, null)
|
||||
} else {
|
||||
val numbers = participants.map { it.phoneNumber }.toTypedArray()
|
||||
val settings = Settings()
|
||||
settings.useSystemSending = true
|
||||
val transaction = Transaction(this, settings)
|
||||
val message = com.klinker.android.send_message.Message(msg, it.phoneNumber)
|
||||
val message = com.klinker.android.send_message.Message(msg, numbers)
|
||||
|
||||
if (attachmentUris.isNotEmpty()) {
|
||||
for (uri in attachmentUris) {
|
||||
val byteArray = contentResolver.openInputStream(uri)?.readBytes() ?: continue
|
||||
val mimeType = contentResolver.getType(uri) ?: continue
|
||||
message.addMedia(byteArray, mimeType)
|
||||
}
|
||||
}
|
||||
|
||||
transaction.sendNewMessage(message, threadId.toLong())
|
||||
|
||||
thread_type_message.setText("")
|
||||
attachmentUris.clear()
|
||||
thread_attachments_holder.beGone()
|
||||
thread_attachments_wrapper.removeAllViews()
|
||||
}
|
||||
}
|
||||
|
||||
thread_type_message.setText("")
|
||||
}
|
||||
|
||||
// show selected contacts, properly split to new lines when appropriate
|
||||
// based on https://stackoverflow.com/a/13505029/1967672
|
||||
|
|
|
@ -1,34 +1,12 @@
|
|||
package com.simplemobiletools.smsmessenger.receivers
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.provider.Telephony
|
||||
import com.simplemobiletools.smsmessenger.extensions.getThreadId
|
||||
import com.simplemobiletools.smsmessenger.extensions.insertNewSMS
|
||||
import com.simplemobiletools.smsmessenger.helpers.MESSAGE_ADDRESS
|
||||
import com.simplemobiletools.smsmessenger.helpers.MESSAGE_BODY
|
||||
import com.klinker.android.send_message.SentReceiver
|
||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||
|
||||
class SmsSentReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val extras = intent.extras
|
||||
if (extras != null) {
|
||||
val address = extras.getString(MESSAGE_ADDRESS) ?: ""
|
||||
val subject = ""
|
||||
val body = extras.getString(MESSAGE_BODY) ?: ""
|
||||
val date = System.currentTimeMillis()
|
||||
val threadId = context.getThreadId(address)
|
||||
val type = if (resultCode == Activity.RESULT_OK) {
|
||||
Telephony.Sms.MESSAGE_TYPE_SENT
|
||||
} else {
|
||||
Telephony.Sms.MESSAGE_TYPE_FAILED
|
||||
}
|
||||
val read = 1
|
||||
context.insertNewSMS(address, subject, body, date, read, threadId, type)
|
||||
}
|
||||
|
||||
class SmsSentReceiver : SentReceiver() {
|
||||
override fun onMessageStatusUpdated(context: Context, intent: Intent, receiverResultCode: Int) {
|
||||
refreshMessages()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue