Android : send an sms from an android application

on Saturday, September 6, 2014


I am developing an android app that sends an sms when a specific signal comes from the bluetooth. Everything works fine up to the point of sending out the sms. I know everything works fine because i have some other functionality in my app that informs me about the received signal. I have also included the SEND_SMS permission to my Manifest.


My code about sending the sms is this:



if((!sendSMS1) && (!sendSMS2)){
Toast.makeText(getApplicationContext(), "Into SMS sent.",
Toast.LENGTH_LONG).show();
if(myphonenumber1 != null){
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(myphonenumber1, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
sendSMS1 = true;
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(myphonenumber2, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
sendSMS2 = true;
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}


I have also tried removing the first condition but nothing happened. Also the sms is not null and at least one of the phone numbers is not null either. Any help will be much appreciated.


0 comments:

Post a Comment