In my application I want to send an sms to a list of contacts. I used this code:
private void sendSMS(String phoneNumber, String message)
{
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
Toast.makeText(getActivity().getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getActivity().getApplicationContext(),
"SMS faild, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
I didn't get any stacktraces, but I never received the message. Are there any formats for the phone number? Or is an emulator not able to send text messages? Any tips on how to actually receive the message are welcome!
Your given code seems correct but here are two quick recommendations:
<uses-permission android:name="android.permission.SEND_SMS"/>
in your app's manifest