如何从广播意图中一一获取所有价值?
how to get all value from broadcast intent one by one?
我正在开发一个必须一次发送多个联系人的应用程序
这是一个短信代码,我在其中发送了不同的索引,但在广播中我只是得到更新,例如,发送 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)`
我正在开发一个必须一次发送多个联系人的应用程序
这是一个短信代码,我在其中发送了不同的索引,但在广播中我只是得到更新,例如,发送 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)`