我正在开发一个应用程序,在该应用程序中,我必须一次发送多个联系人
这是一个短信代码,我在时间上发送不同的索引,但在广播时我只得到更新一个,例如,发送0 1 2,但只得到2作为USER_ID密钥
override fun sendSms(sms: Sms) {
sms.userList.forEachIndexed { index, contact ->
val sentIntent = Intent(SmsService.SENT)
sentIntent.putExtra(SmsService.MESSAGE_ID ,sms.messages.messageId)
sentIntent.putExtra(SmsService.USER_ID , index) // here i am send different index
val sentPI = PendingIntent.getBroadcast(smsService.applicationContext, 0, sentIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
smsManager.sendTextMessage(
contact.phone,
null,
sms.messages.message,
sentPI,
deliveryPI)
} }
// here is the send boadcast code i want to get all index value but i am just getting updated one for example i am sending index 0 1 2 but not getting index 2 so want to retrieve all the value one by one
/************* Sent BroaddCast **************/
private val sentBroadcast =object : BroadcastReceiver(){
override fun onReceive(context: Context?, intent: Intent?) {
println("Send Broadcast")
when(resultCode){
Activity.RESULT_OK ->{
if(intent!=null ) {
val messageId = intent.getLongExtra(MESSAGE_ID, 0)
val userId = intent.getIntExtra(USER_ID, 0)
val scheduleMessage = smsScheduler.getSentMessages()
println("Sucessfull message " + messageId +"userId"+userId)
}
}
}
}}
更改中的0
val sentPI = PendingIntent.getBroadcast(smsService.applicationContext, 0, sentIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
到index
,就像这个
`val sentPI = PendingIntent.getBroadcast(smsService.applicationContext, index, sentIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)`