This is simple code send SMS.
47: SmsManager sms = SmsManager.getDefault();
48: sms.sendTextMessage(\"12345678901\", null, \"hello!\", null, null);
This Problem also Occurs when your msg length exceeds normal text msg length(i.e 160 Character) you need to divide the msg into parts and send... Use this code it may help you
public static void sendSms(Activity curActivity, String phoneNumber, String msg) {
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> msgStringArray = smsManager.divideMessage(msg);
smsManager.sendMultipartTextMessage(phoneNumber, null, msgStringArray, null, null);
}
give the pending intent in your 48th line as given bellow
String sent = "android.telephony.SmsManager.STATUS_ON_ICC_SENT";
PendingIntent piSent = PendingIntent.getBroadcast(smsActivity.this, 0,new Intent(sent), 0);
sms.sendTextMessage("12345678901", null, "hello!", piSent, null);
am sure it works :)
The Null Exception is in the SMS lenght, you may use
try {}catch(Exception ex) {}
in your code in case you get null exception and try send "divided" sms using:
ArrayList<String> parts = sms.divideMessage(message);
sms.sendMultipartTextMessage(telephone, null, parts, null, null);
I had this problem when using special characters in the SMS Message. Changing to normal english characters worked for me.