Al Hennessey
Al Hennessey

Reputation: 2445

SMS not sending in android

i am trying to send an sms text message with my android application, however i am receiving nothing when i run it

here is the code

int minSms = 100001;
    int maxSms = 999998;

    Random rSms = new Random();
    int iSms = rSms.nextInt(maxSms - minSms +1) + minSms;

    try {

        SmsManager sms = SmsManager.getDefault();
        PendingIntent sentPI;
        String SENT = "SMS_SENT";

        sentPI = PendingIntent.getBroadcast(getActivity(), 0,new Intent(SENT), 0);
        sms.sendTextMessage(mobileNumber, null, Integer.toString(iSms), sentPI, null);
        Toast.makeText(getActivity(), "SMS sent.",
                Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(getActivity(),
                "SMS failed, please try again.",
                Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }

I am testing with my own mobile number which i am not going to share but it is in the format 07789123456

Do i need to add any area codes with it, or should it work with the straight 11 digit number?

Upvotes: 1

Views: 619

Answers (1)

Lukas
Lukas

Reputation: 2554

Please take a look at SMS Manager send mutlipart message when there is less than 160 characters . Im pretty sure the text you want to send is to long. Depending on the alphabet (i.e. including emojis) you are using, the message is limited to 70 characters. You have to split the message into a multipart message:

SmsManager sms = SmsManager.getDefault();
ArrayList<String> parts = sms.divideMessage(longMessage);
sms.sendMultipartTextMessage(phoneNumber, null, parts, null, null);

Upvotes: 1

Related Questions