在这里,我创建了一个文本视图,并在该文本视图中存储了多个联系人,然后我通过意图将此文本视图值传递给另一个活动。现在我想向存储在接收到的文本视图中的多个联系人发送短信。我已通过使用以下代码完成此操作..但问题是我只能发送到存储在该 textview 中的第一个号码..所以请建议一些替代代码将其发送给所有存储的联系人。
这是我的代码..
Bundle bundle=intent2.getExtras();
final String getudisp=bundle.getString("InvisibleNum");
String number =getudisp;
sendSMS(number, message);
private void sendSMS(String number, String message) {
Intent sentIntent = new Intent(INTENT_ACTION_SENT);
PendingIntent pendingSentIntent = PendingIntent.getBroadcast(this,
REQUEST_CODE_ACTION_SENT, sentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Intent deliveryIntent = new Intent(INTENT_ACTION_DELIVERY);
PendingIntent pendingDeliveryIntent = PendingIntent.getBroadcast(this,
REQUEST_CODE_ACTION_DELIVERY, deliveryIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
SmsManager smsManager = SmsManager.getDefault();
// Second parameter is the service center number. Use null if you want
// to use the default number
smsManager.sendTextMessage(number, null, message, pendingSentIntent,
pendingDeliveryIntent);
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(smsSentDeliveredReceiver);
}
@Override
protected void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter(INTENT_ACTION_SENT);
filter.addAction(INTENT_ACTION_DELIVERY);
registerReceiver(smsSentDeliveredReceiver, filter);
}
private void initializeReceivers() {
smsSentDeliveredReceiver = new BroadcastReceiver() {
public void onReceive1(Context context, Intent intent) {
processBroadcasts(intent);
}
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
}
};
}
private void processBroadcasts(Intent intent) {
String action = intent.getAction();
Log.i(TAG, "Received: " + action);
if (action.equals(INTENT_ACTION_SENT)) {
Bundle bundle = intent.getExtras();
// Need to check for error messages
Log.i(TAG, "Message: Sent");
Toast.makeText(this, "Message sent", Toast.LENGTH_LONG).show();
} else if (action.equals(INTENT_ACTION_DELIVERY)) {
Bundle bundle = intent.getExtras();
Set<String> keys = bundle.keySet();
// Need to check for error messages
Log.i(TAG, "Message: Delivered");
Toast.makeText(this, "Message delivered", Toast.LENGTH_LONG).show();
}
}