Я пытался получить код результата из sendMultipartTextMessage, вещь, которую я не понимаю, - это если широковещательный приемник работает с sendTextMessage, почему он не работает с sendMultipartTextMessage? Я искал по-разному и смотрел и приводил примеры кода, но просто не видел никаких очевидных причин, почему это не работает. Может ли кто-нибудь пролить свет на это?Широковещательный приемник с sendMultiPartTextMessage
ArrayList<String> messages = sms.divideMessage(text);
int messageCount = messages.size();
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>(messageCount);
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(messageCount);
for (int j = 0; j < messageCount; j++) {
sentIntents.add(
PendingIntent.getBroadcast(context, 0, new Intent(SENT_ACTION),
0));
}
sms.sendMultipartTextMessage(phoneNumber, null, messages, sentIntents, null);
Вот мой BroadcastReceiver
:
private BroadcastReceiver messageSentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(context, "SMS sent", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(context, "Generic failure", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(context, "No service", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(context, "Null PDU", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(context, "Radio off", Toast.LENGTH_SHORT).show();
break;
}
}
};
код выполняется, как показано ниже:
sentIntents = new ArrayList<PendingIntent>();
sentIntent = PendingIntent.getBroadcast(context, 0, new Intent(SENT_ACTION), 0);
deliveredIntent = PendingIntent.getBroadcast(context, 0, new Intent(DELIVERED_ACTION), 0);
context.registerReceiver(messageSentReceiver, new IntentFilter(SENT_ACTION));
context.registerReceiver(messageDeliveredReceiver, new IntentFilter(DELIVERED_ACTION));
Если кто-то может пролить свет на это, я бы очень признателен. Я просто не понимаю, почему это может с sendTextMessage
, но не на sendMultipartTextMessage
.
Спасибо.
Необходимо создать два разных класса. ?? –