sendMultipartTextMessage和监视器发送和接收

时间:2013-02-22 11:09:46

标签: android android-intent android-broadcast smsmanager

我已经阅读了有关如何发送和接收多部分消息的多个线程。我已经实现了以下代码,可以使用!

      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。

让我担心的是:

我有一个PendingIntent sentPi和deliveredPi,已在SMSBroadcastReceiver1SMSBroadcastReceiver2注册。

然后我将它们多次放入ArrayList中,具体取决于消息的持续时间。

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

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

0 个答案:

没有答案