allow sending MMS, sadly it needs internet access

This commit is contained in:
tibbi 2020-04-12 16:00:59 +02:00
parent 2ffdaa0712
commit 554f087d56
3 changed files with 60 additions and 16 deletions

View File

@ -11,6 +11,11 @@
<uses-permission android:name="android.provider.Telephony.SMS_RECEIVED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Internet is needed and used at sending MMS only -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission
android:name="android.permission.USE_FINGERPRINT"
@ -107,6 +112,8 @@
</intent-filter>
</service>
<service android:name="com.android.mms.transaction.TransactionService"/>
<receiver
android:name=".receivers.SmsReceiver"
android:permission="android.permission.BROADCAST_SMS">
@ -126,6 +133,10 @@
</intent-filter>
</receiver>
<receiver
android:name=".receivers.MmsSentReceiver"
android:taskAffinity="com.klinker.android.messaging.MMS_SENT"/>
<receiver
android:name=".receivers.MmsReceiver"
android:exported="true"

View File

@ -6,6 +6,7 @@ import android.content.Intent
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.provider.Telephony
import android.telephony.SmsManager
import android.text.TextUtils
@ -27,6 +28,8 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.klinker.android.send_message.Settings
import com.klinker.android.send_message.Transaction
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
@ -154,22 +157,7 @@ class ThreadActivity : SimpleActivity() {
thread_add_attachment.applyColorFilter(config.textColor)
thread_send_message.setOnClickListener {
val msg = thread_type_message.value
if (msg.isEmpty()) {
return@setOnClickListener
}
participants.forEach {
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)
}
thread_type_message.setText("")
sendMessage()
}
thread_send_message.isClickable = false
@ -346,6 +334,36 @@ class ThreadActivity : SimpleActivity() {
}
}
private fun sendMessage() {
val msg = thread_type_message.value
if (msg.isEmpty()) {
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 settings = Settings()
settings.useSystemSending = true
val transaction = Transaction(this, settings)
val message = com.klinker.android.send_message.Message(msg, it.phoneNumber)
val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, attachmentUris.first())
message.setImage(bitmap)
transaction.sendNewMessage(message, threadId.toLong())
}
}
thread_type_message.setText("")
}
// show selected contacts, properly split to new lines when appropriate
// based on https://stackoverflow.com/a/13505029/1967672
private fun showSelectedContact(views: ArrayList<View>) {

View File

@ -0,0 +1,15 @@
package com.simplemobiletools.smsmessenger.receivers
import android.app.Activity
import android.content.Context
import android.content.Intent
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
class MmsSentReceiver : com.klinker.android.send_message.MmsSentReceiver() {
override fun onMessageStatusUpdated(context: Context?, intent: Intent?, resultCode: Int) {
super.onMessageStatusUpdated(context, intent, resultCode)
if (resultCode == Activity.RESULT_OK) {
refreshMessages()
}
}
}