Android Sms Is Always Sent Same Contact
I am trying to send sms to multiple contacts using asynctask. But when i click send button sms is sent to only one number which is top of the my selected contact list. And number o
Solution 1:
You're always refering to the same contact
variable.
You need to change it with k
list and progress
number like this:
k.get(progress) // your current contact
Change it to something like this:
@Override
protectedfinalString doInBackground(List<kisiler>... lists) {
int progress=0;
finalList<contacts> k=lists[0];
dialog.setMax(k.size());
while (progress<dialog.getMax()){
try{
finalString m=k.get(k.size()-1).getName();
SmsManager smsManager = SmsManager.getDefault();
publishProgress(String.valueOf(k.size()-1),String.valueOf(k.size()),m,String.valueOf(dialog.getMax()));
PendingIntent sendPI = PendingIntent.getBroadcast(getActivity(), 0, new Intent(), 0);
getActivity().registerReceiver(new BroadcastReceiver() {
@Override
publicvoid onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getActivity(),getString(R.string.sent_to_sms)+k.get(progress),Toast.LENGTH_LONG).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getActivity(), R.string.failure+kisi2.getIsim(),Toast.LENGTH_LONG).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getActivity(), R.string.no_service, Toast.LENGTH_LONG).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
break;
}
}
}, new IntentFilter(SENT+m));
smsManager.sendTextMessage(k.get(progress).getNumber(), null, location_information(location), sendPI, null);
}catch (Exception e){
e.printStackTrace();
}
progress++;
}
Post a Comment for "Android Sms Is Always Sent Same Contact"