@@ -3,7 +3,6 @@ package com.httpsms
33import android.app.PendingIntent
44import android.content.Context
55import android.content.Intent
6- import android.content.IntentFilter
76import androidx.work.*
87import com.google.firebase.messaging.FirebaseMessagingService
98import com.google.firebase.messaging.RemoteMessage
@@ -140,15 +139,13 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
140139
141140 val parts = getMessageParts(applicationContext, message)
142141 if (parts.size == 1 ) {
143- return handleSingleMessage(applicationContext, message)
142+ return handleSingleMessage(message)
144143 }
145- return handleMultipartMessage(applicationContext, message, parts)
144+ return handleMultipartMessage(message, parts)
146145 }
147146
148- private fun handleMultipartMessage (context : Context , message : Message , parts : ArrayList <String >): Result {
149- registerReceivers(context, message.id)
150-
151- Timber .d(" sending SMS for message with ID [${message.id} ]" )
147+ private fun handleMultipartMessage (message : Message , parts : ArrayList <String >): Result {
148+ Timber .d(" sending multipart SMS for message with ID [${message.id} ]" )
152149 return try {
153150 val sentIntents = ArrayList <PendingIntent >()
154151 val deliveredIntents = ArrayList <PendingIntent >()
@@ -162,8 +159,8 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
162159 id = message.id
163160 }
164161
165- sentIntents.add(createPendingIntent(id, SmsManagerService .sentAction(id )))
166- deliveredIntents.add(createPendingIntent(id, SmsManagerService .deliveredAction(id )))
162+ sentIntents.add(createPendingIntent(id, SmsManagerService .sentAction()))
163+ deliveredIntents.add(createPendingIntent(id, SmsManagerService .deliveredAction()))
167164 }
168165 SmsManagerService ().sendMultipartMessage(this .applicationContext,message.contact, parts, message.sim, sentIntents, deliveredIntents)
169166 Timber .d(" sent SMS for message with ID [${message.id} ] in [${parts.size} ] parts" )
@@ -176,27 +173,15 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
176173 }
177174
178175
179- private fun handleSingleMessage (context : Context , message : Message ): Result {
180- registerReceivers(context, message.id)
176+ private fun handleSingleMessage (message : Message ): Result {
181177 sendMessage(
182178 message,
183- createPendingIntent(message.id, SmsManagerService .sentAction(message.id )),
184- createPendingIntent(message.id, SmsManagerService .deliveredAction(message.id ))
179+ createPendingIntent(message.id, SmsManagerService .sentAction()),
180+ createPendingIntent(message.id, SmsManagerService .deliveredAction())
185181 )
186182 return Result .success()
187183 }
188184
189- private fun registerReceivers (context : Context , messageID : String ) {
190- context.registerReceiver(
191- SentReceiver (),
192- IntentFilter (SmsManagerService .sentAction(messageID))
193- )
194- context.registerReceiver(
195- DeliveredReceiver (),
196- IntentFilter (SmsManagerService .deliveredAction(messageID))
197- )
198- }
199-
200185 private fun handleFailed (context : Context , messageID : String ) {
201186 Timber .d(" sending failed event for message with ID [${messageID} ]" )
202187 HttpSmsApiService .create(context)
@@ -249,9 +234,9 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
249234
250235 return PendingIntent .getBroadcast(
251236 this .applicationContext,
252- 0 ,
237+ id.hashCode() ,
253238 intent,
254- PendingIntent .FLAG_IMMUTABLE or PendingIntent . FLAG_UPDATE_CURRENT
239+ PendingIntent .FLAG_MUTABLE
255240 )
256241 }
257242 }
0 commit comments