0

I have implemented to Send message of character length is 500,so divided into 160 character messages.

But in that it skips a few message so i added with async task,but still the problem continuous,can help me solve

here is my code,

public class SendMessage
    {

        public static void SendSMS(Activity activity, String Msg)
        {

            try {
                 SmsSendTask mAuthTask=null;
                 mAuthTask = new SmsSendTask(Msg);
                 mAuthTask.execute((Void) null);
            } catch (Exception e) {
                Toast.makeText(activity, "SMS failed, please try again.", Toast.LENGTH_LONG).show();
                System.out.println(e.toString()+"<<e>>>");
                e.printStackTrace();
            }
        }


        public static class SmsSendTask extends AsyncTask<Void, Void, Boolean> {
            private final String _msg;
                SmsSendTask(String msg) {
                _msg = msg;
        }

            @Override
            protected Boolean doInBackground(Void... params) {
                 try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    return false;
                }
                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage("9246591931", null, _msg, null, null);
                return true;
            }

            @Override
            protected void onPostExecute(final Boolean success) {
                if (success) {
                } else {
                }
            }

            @Override
            protected void onCancelled() {
            }
        }
    }
Rashmi S
  • 267
  • 1
  • 7
  • 20
  • you can get your answer in this link http://stackoverflow.com/a/6590782/1896677 – Bhavikkumar Mar 22 '16 at 12:37
  • 1
    Possible duplicate of [How to send the SMS more than 160 character?](http://stackoverflow.com/questions/6580675/how-to-send-the-sms-more-than-160-character) – kawashita86 Mar 22 '16 at 12:40

1 Answers1

0
    String body="this is my message";
    SmsManager sms = SmsManager.getDefault();
    ArrayList<String>arraylist = new ArrayList<String>();
    arraylist=sms.divideMessage(body);
    try
    {
        sms.sendMultipartTextMessage(address, null,arraylist, null,null);

    }
    catch (Exception e)
    {

    }