mirror of
				https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
				synced 2025-06-05 21:49:22 +02:00 
			
		
		
		
	properly handle and show received MMS
This commit is contained in:
		| @@ -39,4 +39,5 @@ dependencies { | ||||
|     implementation 'com.simplemobiletools:commons:5.25.2' | ||||
|     implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4' | ||||
|     implementation 'org.greenrobot:eventbus:3.2.0' | ||||
|     implementation 'com.klinkerapps:android-smsmms:5.2.6' | ||||
| } | ||||
|   | ||||
| @@ -3,13 +3,13 @@ | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     package="com.simplemobiletools.smsmessenger"> | ||||
|  | ||||
|     <uses-permission android:name="android.permission.SEND_SMS" /> | ||||
|     <uses-permission android:name="android.permission.RECEIVE_SMS" /> | ||||
|     <uses-permission android:name="android.permission.READ_SMS" /> | ||||
|     <uses-permission android:name="android.permission.WRITE_SMS" /> | ||||
|     <uses-permission android:name="android.permission.SEND_SMS" /> | ||||
|     <uses-permission android:name="android.permission.RECEIVE_SMS" /> | ||||
|     <uses-permission android:name="android.permission.RECEIVE_MMS" /> | ||||
|     <uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" /> | ||||
|     <uses-permission android:name="android.provider.Telephony.SMS_RECEIVED" /> | ||||
|     <uses-permission android:name="android.permission.WAKE_LOCK" /> | ||||
|  | ||||
|     <uses-permission android:name="android.permission.READ_CONTACTS" /> | ||||
|     <uses-permission | ||||
| @@ -109,14 +109,20 @@ | ||||
|         </receiver> | ||||
|  | ||||
|         <receiver | ||||
|             android:name=".receivers.MmsReceiver" | ||||
|             android:name="com.android.mms.transaction.PushReceiver" | ||||
|             android:permission="android.permission.BROADCAST_WAP_PUSH"> | ||||
|             <intent-filter> | ||||
|                 <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" /> | ||||
|                 <data android:mimeType="application/vnd.wap.mms-message" /> | ||||
|                 <data android:mimeType="application/vnd.wap.sic" /> | ||||
|             </intent-filter> | ||||
|         </receiver> | ||||
|  | ||||
|         <receiver | ||||
|             android:name=".receivers.MmsReceiver" | ||||
|             android:exported="true" | ||||
|             android:taskAffinity="com.klinker.android.messaging.MMS_RECEIVED"/> | ||||
|  | ||||
|         <receiver android:name=".receivers.SmsSentReceiver" /> | ||||
|  | ||||
|         <activity-alias | ||||
|   | ||||
| @@ -424,7 +424,7 @@ fun Context.isNumberBlocked(number: String): Boolean { | ||||
| } | ||||
|  | ||||
| @SuppressLint("NewApi") | ||||
| fun Context.showReceivedMessageNotification(address: String, body: String, threadID: Int) { | ||||
| fun Context.showReceivedMessageNotification(address: String, body: String, threadID: Int, bitmap: Bitmap? = null) { | ||||
|     val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||||
|     val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) | ||||
|     val channelId = "simple_sms_messenger" | ||||
| @@ -454,12 +454,12 @@ fun Context.showReceivedMessageNotification(address: String, body: String, threa | ||||
|     val summaryText = getString(R.string.new_message) | ||||
|     val sender = getNameFromPhoneNumber(address) | ||||
|  | ||||
|     val firstLetter = sender.toCharArray().getOrNull(0)?.toString() ?: "S" | ||||
|     val largeIcon = bitmap ?: getNotificationLetterIcon(sender.toCharArray().getOrNull(0)?.toString() ?: "S") | ||||
|     val builder = NotificationCompat.Builder(this, channelId) | ||||
|         .setContentTitle(sender) | ||||
|         .setContentText(body) | ||||
|         .setSmallIcon(R.drawable.ic_messenger) | ||||
|         .setLargeIcon(getNotificationLetterIcon(firstLetter)) | ||||
|         .setLargeIcon(largeIcon) | ||||
|         .setStyle(NotificationCompat.BigTextStyle().setSummaryText(summaryText).bigText(body)) | ||||
|         .setContentIntent(pendingIntent) | ||||
|         .setPriority(NotificationCompat.PRIORITY_MAX) | ||||
|   | ||||
| @@ -1,11 +1,35 @@ | ||||
| package com.simplemobiletools.smsmessenger.receivers | ||||
|  | ||||
| import android.content.BroadcastReceiver | ||||
| import android.content.Context | ||||
| import android.content.Intent | ||||
| import android.net.Uri | ||||
| import com.bumptech.glide.Glide | ||||
| import com.simplemobiletools.commons.helpers.ensureBackgroundThread | ||||
| import com.simplemobiletools.smsmessenger.R | ||||
| import com.simplemobiletools.smsmessenger.extensions.getLatestMMS | ||||
| import com.simplemobiletools.smsmessenger.extensions.showReceivedMessageNotification | ||||
|  | ||||
| class MmsReceiver : BroadcastReceiver() { | ||||
|     override fun onReceive(context: Context, intent: Intent) { | ||||
| // more info at https://github.com/klinker41/android-smsmms | ||||
| class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() { | ||||
|     override fun onMessageReceived(context: Context, messageUri: Uri) { | ||||
|         val mms = context.getLatestMMS() ?: return | ||||
|         val address = mms.participants.firstOrNull()?.phoneNumber ?: "" | ||||
|         val size = context.resources.getDimension(R.dimen.notification_large_icon_size).toInt() | ||||
|  | ||||
|         ensureBackgroundThread { | ||||
|             val glideBitmap = try { | ||||
|                 Glide.with(context) | ||||
|                     .asBitmap() | ||||
|                     .load(mms.attachment!!.uri) | ||||
|                     .centerCrop() | ||||
|                     .into(size, size) | ||||
|                     .get() | ||||
|             } catch (e: Exception) { | ||||
|                 null | ||||
|             } | ||||
|  | ||||
|             context.showReceivedMessageNotification(address, mms.body, mms.thread, glideBitmap) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun onError(context: Context, error: String) {} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user