Skip to content Skip to sidebar Skip to footer

Sendtextmessage In Android Phone

This is simple code send SMS. 47: SmsManager sms = SmsManager.getDefault(); 48: sms.sendTextMessage('12345678901', null, 'hello!', null, null); But I can't run this code. This cod

Solution 1:

give the pending intent in your 48th line as given bellow

Stringsent="android.telephony.SmsManager.STATUS_ON_ICC_SENT";
PendingIntentpiSent= PendingIntent.getBroadcast(smsActivity.this, 0,newIntent(sent), 0);

sms.sendTextMessage("12345678901", null, "hello!", piSent, null);

am sure it works :)

Solution 2:

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

publicstaticvoidsendSms(Activity curActivity, String phoneNumber, String msg) {
 SmsManager smsManager = SmsManager.getDefault(); 

 ArrayList<String> msgStringArray = smsManager.divideMessage(msg);      

 smsManager.sendMultipartTextMessage(phoneNumber, null, msgStringArray, null, null);
}

Solution 3:

I had this problem when using special characters in the SMS Message. Changing to normal english characters worked for me.

Solution 4:

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);

Post a Comment for "Sendtextmessage In Android Phone"