Putting aside your application seems like a spam bot, here is how I would implement it.
Using a for
or while
loop is probably what you are looking for.
(Where noSends
is the amount of times you wish to send the message)
public void sendMultiple(int noSends){
String phoneNo = phoneInput.getText().toString();
String sms = textSMS.getText().toString();
try
{
SmsManager smsManager = SmsManager.getDefault();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
for(int i = noSends; i != 0; i--)
{
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
}
if( prefs.getBoolean("addvalues", true) )
{
ContentValues values = new ContentValues();
values.put("address", phoneNo);
values.put("body", sms);
while(noSends != 0)
{
getContentResolver().insert(Uri.parse("content://sms/sent"), values);
noSends--;
}
}
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(),getString(R.string.messageNotSent), Toast.LENGTH_LONG).show();
e.printStackTrace();
{
else
{
Toast.makeText(getApplicationContext(),getString(R.string.sentMessages), Toast.LENGTH_LONG).show();
}
}