RSS

Code to handle sending sms above 160 characters

26 Oct
public void textSingle(View view) {
sendSMS("XXXXXXXXXX", "Test", false);
}

public void textSingleLong(View view) {
sendSMS("XXXXXXXXXX",
"TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest",
false);
}

public void textMulti(View view) {
sendSMS("XXXXXXXXXX",
"TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest",
true);
}

private void sendSMS(String phoneNo, String message, boolean split) {
...

SmsManager sms = SmsManager.getDefault();
if (!split) {
Log.d("SMSTest", "Sending single message: " + message);
sms.sendTextMessage(phoneNo, null, message, sentPI, deliveredPI);
} else {
Log.d("SMSTest", "Sending '" + message + "' in multiple parts.");
ArrayList<String> parts = sms.divideMessage(message);
Log.d("SMSTest", parts.size() + " parts:");
for (String string : parts) {
Log.d("SMSTest", string);
}
ArrayList<PendingIntent> sentList = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveredList = new ArrayList<PendingIntent>();
for (int i = 0; i &lt; parts.size(); i++) {
sentList.add(sentPI);
deliveredList.add(deliveredPI);
}
sms.sendMultipartTextMessage(phoneNo, null, parts, sentList,
deliveredList);
}
}

Reference: http://stackoverflow.com/questions/7898773/crashes-when-sending-sms-nullpointerexception-what-should-i-do

Advertisements
 
Leave a comment

Posted by on October 26, 2012 in Android Source Code

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: