2

I have some code to send SMS from my application but this code only send 160 characters and cannot send more than 160. This is my code :

protected void sendMessage(String message){

        String phoneNumber = "xxxx";

        try {

            if(message.length() < 161){
                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage(phoneNumber, null, message, null, null);

                Toast.makeText(getApplicationContext(), "SMS Send !", Toast.LENGTH_LONG).show();
            }else{
                Toast.makeText(getApplicationContext(), "Character too long !", Toast.LENGTH_LONG).show();
            }

        }catch (Exception e){
            Toast.makeText(getApplicationContext(), "SMS Failed !", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }

    }

How to send SMS with more than 160 characters ?

Nicholas
  • 119
  • 2
  • 17

2 Answers2

5

Send like this without worrying of its size.

 protected void sendMessage(String message) {
        try {
            String phoneNumber = "xxxx";
            SmsManager smsManager = SmsManager.getDefault();

            ArrayList<String> parts = smsManager.divideMessage(message);
            //smsManager.sendTextMessage(phoneNumber, null, message, null, null);
            smsManager.sendMultipartTextMessage(phoneNumber, null, parts,
                    null, null);
            Toast.makeText(getApplicationContext(), "SMS Send !", Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "SMS Failed !", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
0

Send the message over 2 texts. SMS has a limit of 160.

James Wood
  • 17,286
  • 4
  • 46
  • 89