5

我已经阅读了有关如何发送和接收多部分消息的多个主题。我已经实现了以下代码并且它有效!

      PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
      PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);
        //---when the SMS has been sent---
        registerReceiver(SMSBroadcastReceiver1, new IntentFilter(SENT));
        //---when the SMS has been delivered---
        registerReceiver(SMSBroadcastReceiver2, new IntentFilter(DELIVERED));    


    SmsManager smsManager = SmsManager.getDefault();
    ArrayList<String> parts = smsManager.divideMessage(smsToSend);

    ArrayList<PendingIntent> sentList = new ArrayList<PendingIntent>();
    ArrayList<PendingIntent> deliveredList = new ArrayList<PendingIntent>();
    for (int i = 0; i < parts.size(); i++) {
        sentList.add(sentPI);
        deliveredList.add(deliveredPI);
    }


    //smsManager.sendTextMessage(phoneNumber, null, smsToSend, sentPI, deliveredPI);
    smsManager.sendMultipartTextMessage(phoneNumber, null, parts, sentList, deliveredList);

我有一个注册的 SMSBroadcastReceiver2 和 SMSBroadcastReceiver1。

让我担心的是:

我有一个PendingIntentsentPi 和deliveredPi,它是用SMSBroadcastReceiver1and注册的SMSBroadcastReceiver2

然后我将它们多次放入 ArrayList 中,具体取决于消息的长度。

这是一件好事吗?或者我应该对消息的每个部分有不同的意图和接收者。

接收器什么时候在我的代码中触发?我注意到它只在发送消息和接收消息时触发一次(我将它们编码为在那些时刻显示 Toast 消息),无论消息有多长。是在第一部分交付时还是最后...?

4

0 回答 0