Trying to ID the SMS delivery confirmation

后端 未结 1 2048
南笙
南笙 2020-12-22 13:38

I am currently trying to get the confirmation for each sended SMS. I need to be sure that my SMS are send, so I used a BroadCastReceived to get the information

相关标签:
1条回答
  • 2020-12-22 14:28

    Your problem is due the fact that PendingIntents can be reused by the system, if certain things about the requests are not different. In your code, you're passing FLAG_UPDATE_CURRENT, which is causing the stored Intent and its extras to be updated each time a PendingIntent is requested. This is why you're getting id : 3 for each of the messages. To correct this, you can call getBroadcast() with a unique request code (the second parameter) each time, which will create a new PendingIntent for each request, each with a separate Intent with their own extras.

    In your case, the fix should be simple, assuming that idSms is unique for each message.

    PendingIntent sentPI = PendingIntent.getBroadcast(getApplicationContext(),
                                                      Integer.parseInt(idSms),
                                                      sentIntent,
                                                      PendingIntent.FLAG_UPDATE_CURRENT);
    
    0 讨论(0)
提交回复
热议问题