mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
Merge pull request #619 from Naveen3Singh/sms_mms_improvements
Fix MMS issues
This commit is contained in:
@@ -38,18 +38,24 @@ fun Context.sendMessageCompat(text: String, addresses: List<String>, subId: Int?
|
|||||||
settings.subscriptionId = subId
|
settings.subscriptionId = subId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val messagingUtils = messagingUtils
|
||||||
val isMms = attachments.isNotEmpty() || isLongMmsMessage(text, settings) || addresses.size > 1 && settings.group
|
val isMms = attachments.isNotEmpty() || isLongMmsMessage(text, settings) || addresses.size > 1 && settings.group
|
||||||
if (isMms) {
|
if (isMms) {
|
||||||
// we send all MMS attachments separately to reduces the chances of hitting provider MMS limit.
|
// we send all MMS attachments separately to reduces the chances of hitting provider MMS limit.
|
||||||
if (attachments.size > 1) {
|
if (attachments.isNotEmpty()) {
|
||||||
for (i in 0 until attachments.lastIndex) {
|
val lastIndex = attachments.lastIndex
|
||||||
val attachment = attachments[i]
|
if (attachments.size > 1) {
|
||||||
messagingUtils.sendMmsMessage("", addresses, listOf(attachment), settings)
|
for (i in 0 until lastIndex) {
|
||||||
|
val attachment = attachments[i]
|
||||||
|
messagingUtils.sendMmsMessage("", addresses, attachment, settings)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val lastAttachment = attachments[attachments.lastIndex]
|
val lastAttachment = attachments[lastIndex]
|
||||||
messagingUtils.sendMmsMessage(text, addresses, listOf(lastAttachment), settings)
|
messagingUtils.sendMmsMessage(text, addresses, lastAttachment, settings)
|
||||||
|
} else {
|
||||||
|
messagingUtils.sendMmsMessage(text, addresses, null, settings)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
messagingUtils.sendSmsMessage(text, addresses.toSet(), settings.subscriptionId, settings.deliveryReports)
|
messagingUtils.sendSmsMessage(text, addresses.toSet(), settings.subscriptionId, settings.deliveryReports)
|
||||||
|
@@ -133,29 +133,27 @@ class MessagingUtils(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("TODO: Move/rewrite MMS code into the app.")
|
@Deprecated("TODO: Move/rewrite MMS code into the app.")
|
||||||
fun sendMmsMessage(text: String, addresses: List<String>, attachments: List<Attachment>, settings: Settings) {
|
fun sendMmsMessage(text: String, addresses: List<String>, attachment: Attachment?, settings: Settings) {
|
||||||
val transaction = Transaction(context, settings)
|
val transaction = Transaction(context, settings)
|
||||||
val message = Message(text, addresses.toTypedArray())
|
val message = Message(text, addresses.toTypedArray())
|
||||||
|
|
||||||
if (attachments.isNotEmpty()) {
|
if (attachment != null) {
|
||||||
for (attachment in attachments) {
|
try {
|
||||||
try {
|
val uri = attachment.getUri()
|
||||||
val uri = attachment.getUri()
|
context.contentResolver.openInputStream(uri)?.use {
|
||||||
context.contentResolver.openInputStream(uri)?.use {
|
val bytes = it.readBytes()
|
||||||
val bytes = it.readBytes()
|
val mimeType = if (attachment.mimetype.isPlainTextMimeType()) {
|
||||||
val mimeType = if (attachment.mimetype.isPlainTextMimeType()) {
|
"application/txt"
|
||||||
"application/txt"
|
} else {
|
||||||
} else {
|
attachment.mimetype
|
||||||
attachment.mimetype
|
|
||||||
}
|
|
||||||
val name = attachment.filename
|
|
||||||
message.addMedia(bytes, mimeType, name, name)
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
val name = attachment.filename
|
||||||
context.showErrorToast(e)
|
message.addMedia(bytes, mimeType, name, name)
|
||||||
} catch (e: Error) {
|
|
||||||
context.showErrorToast(e.localizedMessage ?: context.getString(R.string.unknown_error_occurred))
|
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
context.showErrorToast(e)
|
||||||
|
} catch (e: Error) {
|
||||||
|
context.showErrorToast(e.localizedMessage ?: context.getString(R.string.unknown_error_occurred))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user