0
왜 내 수신자가 여러 번 전화 했습니까? 아래의 코드는 잘 작동하지만 delete 메소드는 여러 번 호출됩니다. 아래의 메소드는 AWS SQS에서 메시지를 보내고 삭제하기 전에 SMS 상태를 감지하는 것입니다 ...SMS 상태 BroadcastReceiver가 여러 번 호출되었습니다.
void send(String msgbody, String msg_receipients, Intent intent,
final Context context, final Message message,
final AmazonSQSClient sqsClient, final String queueUrl) {
String SENT = "SMS_SENT";
Intent sent_ = new Intent(SENT);
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, sent_, 0);
ArrayList<PendingIntent> sentPendingIntents = new ArrayList<PendingIntent>();
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent intent) {
if (getResultCode() == Activity.RESULT_OK) {
new Thread(new Runnable() {
@Override
public void run() {
Delete(message, sqsClient, queueUrl);
}
}).start();
} else {
Log.d(TAG, "Message Failed. Error Code: " + getResultCode());
}
}
}, new IntentFilter(SENT));
SmsManager smsmgr = SmsManager.getDefault();
final ArrayList<String> messages = smsmgr.divideMessage(msgbody);
final int c = messages.size();
try {
Log.d(TAG, "Sending messages to: " + msg_receipients);
for (int i = 0; i < c; i++) {
final String m = messages.get(i);
Log.d(TAG, "divided messages: " + m);
sentPendingIntents.add(i, sentPI);
}
smsmgr.sendMultipartTextMessage(msg_receipients, null, messages,
sentPendingIntents, null);
} catch (Exception e) {
Log.e(TAG, "unexpected error", e);
}
}