通过编程发送大量短信-传递报告有问题

pbossiut  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(376)

我有一个android应用程序,可以在短时间内发送大量消息,并且该应用程序需要处理交付报告。这一切都很好,应用程序运行稳定,没有任何崩溃,消息被发送,交付报告工作正常。。。好一段时间了。
假设我在一条消息之后发送一条消息(前一条消息之后的每条消息都已成功发送-我正在查看smssent PendingEvent-只有当hasonprogresssend==false时,我才能发送新消息)。交付报告可以正常工作约1-2小时。然后,交付报告的行为异常。不断地删除几个交付报告。
因此,在发送完成后,大约7小时后,大约8000条短信的发送报告会停止发送,但是收到了很多短信,但应用程序没有收到发送报告。
但现在出现了奇怪的部分:)。第二天,我又做了一次测试,又发了8000条短信。邮件会立即发送给收件人,但我收到的是前一天的传递报告,而不是前一天的。我试着换了我的sim卡,还收到了前一天发送的邮件。
在我重新启动应用程序后,一切都是一样的,从最后一天的交付报告。但在我重新启动设备后,它的表现仍与前一天一样(大约1-2小时工作正常,然后交付报告的速度大大降低)。
所以总结一下:我收到的交付报告很好,直到看起来某个设备队列已满。在此之后,交付报告非常缓慢。又过了一天,当我再次开始发送(使用新的sim卡)时,我的delivery broadcastreceiver从昨天发送的邮件中获取了昨天未发送的邮件的发送报告。重新启动后,应用程序是相同的。重新启动设备后,它开始像第一天一样工作。因此,如果我的BrodactReceiver在我的活动的oncreate方法中注册,并且应用程序重新启动没有帮助,那么这一定是一些android队列问题,我需要在我的应用程序中以某种方式处理这些问题(可能是为了减慢发送速度,成功发送消息后再延迟一段时间,或者如果多条未发送的消息大于某个值,则停止发送?)
谢谢,很抱歉问了这么大的问题:)
我在oncreate中注册了两个BroadCars接收器:

  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. ... check all persmissions
  5. receiverSentGlobal = new BroadcastReceiver() {
  6. @Override
  7. public void onReceive(Context context, Intent intent) {
  8. hasOnProgressSend = false;
  9. JSONObject currentMsgSentStatus = new JSONObject();
  10. try {
  11. currentMsgSentStatus.put("msg_id", intent.getStringExtra("msg_id"));
  12. currentMsgSentStatus.put("sim_id", intent.getStringExtra("sim_id"));
  13. } catch (JSONException e) {
  14. e.printStackTrace();
  15. }
  16. switch (getResultCode()) {
  17. case Activity.RESULT_OK:
  18. try {
  19. currentMsgSentStatus.put("status", "OK");
  20. } catch (JSONException e) {
  21. e.printStackTrace();
  22. }
  23. break;
  24. case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
  25. try {
  26. currentMsgSentStatus.put("status", "GENERIC_FAILURE");
  27. } catch (JSONException e) {
  28. e.printStackTrace();
  29. }
  30. break;
  31. case SmsManager.RESULT_ERROR_NO_SERVICE:
  32. try {
  33. currentMsgSentStatus.put("status", "NO_SERVICE");
  34. } catch (JSONException e) {
  35. e.printStackTrace();
  36. }
  37. break;
  38. case SmsManager.RESULT_ERROR_NULL_PDU:
  39. try {
  40. currentMsgSentStatus.put("status", "NULL_PDU");
  41. } catch (JSONException e) {
  42. e.printStackTrace();
  43. }
  44. break;
  45. case SmsManager.RESULT_ERROR_RADIO_OFF:
  46. try {
  47. currentMsgSentStatus.put("status", "RADIO_OFF");
  48. } catch (JSONException e) {
  49. e.printStackTrace();
  50. }
  51. break;
  52. }
  53. sendStatus.put(currentMsgSentStatus);
  54. }
  55. };
  56. registerReceiver(receiverSentGlobal, new IntentFilter(ACTION_SMS_SENT));
  57. receiverDeliveryGlobal = new BroadcastReceiver() {
  58. @RequiresApi(api = Build.VERSION_CODES.Q)
  59. @Override
  60. public void onReceive(Context context, Intent intent) {
  61. JSONObject currentMsgDeliveryStatus = new JSONObject();
  62. try {
  63. currentMsgDeliveryStatus.put("msg_id", intent.getStringExtra("msg_id"));
  64. currentMsgDeliveryStatus.put("sim_id", intent.getStringExtra("sim_id"));
  65. } catch (JSONException e) {
  66. e.printStackTrace();
  67. }
  68. switch (getResultCode()) {
  69. case Activity.RESULT_OK:
  70. try {
  71. currentMsgDeliveryStatus.put("status", "DELIVERED");
  72. } catch (JSONException e) {
  73. e.printStackTrace();
  74. }
  75. break;
  76. case Activity.RESULT_CANCELED:
  77. try {
  78. currentMsgDeliveryStatus.put("status", "CANCELED");
  79. } catch (JSONException e) {
  80. e.printStackTrace();
  81. }
  82. break;
  83. }
  84. deliveryStatus.put(currentMsgDeliveryStatus);
  85. }
  86. };
  87. registerReceiver(receiverDeliveryGlobal, new IntentFilter(ACTION_SMS_DELIVERED));
  88. ...
  89. }

我的sendsms方法:

  1. SmsManager sm;
  2. ... there is also some code to handle subscription, but let's make it more simple
  3. sm = SmsManager.getDefault();
  4. ArrayList<String> parts = sm.divideMessage(msg);
  5. Intent iSent = new Intent(ACTION_SMS_SENT);
  6. iSent.putExtra("msg_id", msgId);
  7. iSent.putExtra("sim_id", String.valueOf(lastSendSimId));
  8. PendingIntent piSent = PendingIntent.getBroadcast(this, Integer.parseInt(msgId), iSent, PendingIntent.FLAG_ONE_SHOT);
  9. //Intent iDel = new Intent(ACTION_SMS_DELIVERED+msgId);
  10. Intent iDel = new Intent(ACTION_SMS_DELIVERED);
  11. iDel.putExtra("msg_id", msgId);
  12. iDel.putExtra("sim_id", String.valueOf(lastSendSimId));
  13. PendingIntent piDel = PendingIntent.getBroadcast(this, Integer.parseInt(msgId), iDel, PendingIntent.FLAG_ONE_SHOT);
  14. if (parts.size() == 1)
  15. {
  16. msg = parts.get(0);
  17. sm.sendTextMessage(number, null, msg, piSent, piDel);
  18. }
  19. else
  20. {
  21. ArrayList<PendingIntent> sentPis = new ArrayList<PendingIntent>();
  22. ArrayList<PendingIntent> delPis = new ArrayList<PendingIntent>();
  23. int ct = parts.size();
  24. for (int i = 0; i < ct; i++)
  25. {
  26. sentPis.add(i, piSent);
  27. delPis.add(i, piDel);
  28. }
  29. sm.sendMultipartTextMessage(number, null, parts, sentPis, delPis);
  30. }
  31. hasOnProgressSend = true;

编辑1:刚找到-通过向2个号码发送消息进行测试。a号在在线设备中,b号在关机设备中。直到大约250封未送达b的邮件,应用程序才收到a的送达报告。在250封未送达的邮件之后,将停止向应用发送a的送达通知。为b通电后,发送到a的所有消息都会收到所有通知。因此,大约有250个等待交付报告的队列。有没有办法将交货期限制在10分钟左右?

iezvtpos

iezvtpos1#

好的,发现问题了。设备上大约有250个待定的交付意图。因此,我需要以某种方式限制或取消旧的交付挂起的意图。

相关问题