mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-12 01:30:44 +01:00
Merge pull request #619 from Naveen3Singh/sms_mms_improvements
Fix MMS issues
This commit is contained in:
commit
8eb5d7e7af
@ -38,18 +38,24 @@ fun Context.sendMessageCompat(text: String, addresses: List<String>, subId: Int?
|
||||
settings.subscriptionId = subId
|
||||
}
|
||||
|
||||
val messagingUtils = messagingUtils
|
||||
val isMms = attachments.isNotEmpty() || isLongMmsMessage(text, settings) || addresses.size > 1 && settings.group
|
||||
if (isMms) {
|
||||
// we send all MMS attachments separately to reduces the chances of hitting provider MMS limit.
|
||||
if (attachments.size > 1) {
|
||||
for (i in 0 until attachments.lastIndex) {
|
||||
val attachment = attachments[i]
|
||||
messagingUtils.sendMmsMessage("", addresses, listOf(attachment), settings)
|
||||
if (attachments.isNotEmpty()) {
|
||||
val lastIndex = attachments.lastIndex
|
||||
if (attachments.size > 1) {
|
||||
for (i in 0 until lastIndex) {
|
||||
val attachment = attachments[i]
|
||||
messagingUtils.sendMmsMessage("", addresses, attachment, settings)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val lastAttachment = attachments[attachments.lastIndex]
|
||||
messagingUtils.sendMmsMessage(text, addresses, listOf(lastAttachment), settings)
|
||||
val lastAttachment = attachments[lastIndex]
|
||||
messagingUtils.sendMmsMessage(text, addresses, lastAttachment, settings)
|
||||
} else {
|
||||
messagingUtils.sendMmsMessage(text, addresses, null, settings)
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
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.")
|
||||
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 message = Message(text, addresses.toTypedArray())
|
||||
|
||||
if (attachments.isNotEmpty()) {
|
||||
for (attachment in attachments) {
|
||||
try {
|
||||
val uri = attachment.getUri()
|
||||
context.contentResolver.openInputStream(uri)?.use {
|
||||
val bytes = it.readBytes()
|
||||
val mimeType = if (attachment.mimetype.isPlainTextMimeType()) {
|
||||
"application/txt"
|
||||
} else {
|
||||
attachment.mimetype
|
||||
}
|
||||
val name = attachment.filename
|
||||
message.addMedia(bytes, mimeType, name, name)
|
||||
if (attachment != null) {
|
||||
try {
|
||||
val uri = attachment.getUri()
|
||||
context.contentResolver.openInputStream(uri)?.use {
|
||||
val bytes = it.readBytes()
|
||||
val mimeType = if (attachment.mimetype.isPlainTextMimeType()) {
|
||||
"application/txt"
|
||||
} else {
|
||||
attachment.mimetype
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.showErrorToast(e)
|
||||
} catch (e: Error) {
|
||||
context.showErrorToast(e.localizedMessage ?: context.getString(R.string.unknown_error_occurred))
|
||||
val name = attachment.filename
|
||||
message.addMedia(bytes, mimeType, name, name)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.showErrorToast(e)
|
||||
} catch (e: Error) {
|
||||
context.showErrorToast(e.localizedMessage ?: context.getString(R.string.unknown_error_occurred))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user