39

How to send big SMS in android. I used :

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(contactNos[j], null,msgs[i], sentPI, deliveredPI);

this code work only for 160 character message. i also use

ArrayList<String> msgsplit=sms.divideMessage(msgs[i]);
ArrayList<PendingIntent> listOfIntents = new ArrayList<PendingIntent>(); 

for (int k=0; k < msgsplit.size(); k++){  
    Intent sentIntent = new Intent(); 
    PendingIntent pi = PendingIntent.getBroadcast(MultipleMsg.this, 0, sentIntent, PendingIntent.FLAG_CANCEL_CURRENT);  
    listOfIntents.add(pi);  
}
// sendMessage(contactNos[j],msgs[i]);
sms.sendMultipartTextMessage(contactNos[j],null,msgsplit, listOfIntents, null);

But it sends junk character in the message. Can anyone help me?

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
Girish Bhutiya
  • 3,111
  • 5
  • 31
  • 50

4 Answers4

51

Try below code might help

SmsManager sms = SmsManager.getDefault();
ArrayList<String> parts = sms.divideMessage(message);
sms.sendMultipartTextMessage(phoneNumber, null, parts, null, null);
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
35

Junk characters? method sendMultipartTextMessage only send text message. If you want to send non text message, you should look to method sendDataMessage. Below is the code excerpt from android cts. It has example on how to send long messages.

SmsManager sm = SmsManager.getDefault();
ArrayList<String> parts =sm.divideMessage(LONG_TEXT);
int numParts = parts.size();

ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();

for (int i = 0; i < numParts; i++) {
sentIntents.add(PendingIntent.getBroadcast(getContext(), 0, mSendIntent, 0));
deliveryIntents.add(PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, 0));
}

sm.sendMultiPartTextMessage(mDestAddr,null, parts, sentIntents, deliveryIntents)
Jasonw
  • 5,054
  • 7
  • 43
  • 48
  • I already try this and also put it in my question. No doubt this code split message and send it but at other side message comes with some unsupported characters in message. – Girish Bhutiya Jul 08 '11 at 06:04
  • seem like similar to the issue you encounter but they claim on simulator only. http://code.google.com/p/android/issues/detail?id=13737 – Jasonw Jul 08 '11 at 07:38
  • yap i also have same problem but i can't understand what's he said for send long message with out junk character. – Girish Bhutiya Jul 08 '11 at 09:03
  • 1
    this work on real device. Device not send junk character & work fine without any problem. – Girish Bhutiya Sep 13 '11 at 07:55
3

The emulator send the junk characters in that code during certain problem so use apk in real mobile , and check the code , I am sure that your application will not send junk message..All the best.

tizbn
  • 1,907
  • 11
  • 16
0

You should get specific Short Code from SMSC, for sending SMS which having characters more than 160.

krishna Ram
  • 639
  • 3
  • 9
  • 20