0

I've got some problem with sending sms from Android app. In strings.xml I have text1 and text2 with some text. When I'm trying to send sms with only one string, e.g

sms.sendTextMessage(number, null,message, null,null);

where message i getString(R.string.text1) it works fine. But what I need is send String text = getString(R.string.text1) + someVariable + getString(R.string.text2); but it doesn't work. I've tried to make getResources().getString() in both but still nothing, it's not sending;/ What am I doing wrong?

waclab1807
  • 71
  • 5
  • What is your problem? you can sand any message but this specific messsage fail? – Thiago Souto Jun 02 '15 at 16:28
  • 1
    If your concatenated String is over the character limit, you'll need to use the `sendMultipartTextMessage()` method. `sendTextMessage()` will just fail silently in that case. – Mike M. Jun 02 '15 at 16:29
  • 1
    Oh, I didn't even think about char limit, and also didn't know sendMultipartTextMessage() method, thanks a lot, this helps! – waclab1807 Jun 02 '15 at 16:34

1 Answers1

0

You can use String Builder to append all those string and put it together.

StringBuilder sb = new StringBuilder(some_appropriate_size);
sb.append(getResources().getString(R.string.text1));
sb.append(someVariable);
sb.append(getResources().getString(R.string.text2));

String final_string =  sb.toString(); 
Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50