Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello, guys, I am working on android app and an android app, i want to send SMS through my app but when I click on button so am getting an error
SMS failed, please try again later!
please help me how can I solve it

What I have tried:

 @Override
            public void onClick(View v) {

                String phoneNo = textPhoneNo.getText().toString();
                String sms = textSMS.getText().toString();

                try {
                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage(phoneNo, null, sms, null, null);
                    Toast.makeText(getApplicationContext(), "SMS Sent!",
                            Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(),
                            "SMS faild, please try again later!",
                            Toast.LENGTH_LONG).show();
                    e.printStackTrace();
                }

            }
        });
    }
}
Posted
Comments
Richard MacCutchan 22-Jan-18 10:47am    
Your message is no use to anyone since it provides no details as to what exception was raised or why. Please use your debugger and inspect the exception to find out what happened.
Member 9983063 22-Jan-18 11:01am    
please leave to use codeproject it's my humble request
David_Wimbley 22-Jan-18 13:38pm    
Richard provided you valuable response. You provided a generic error that is of no use to anyone...look at what the Exception in your catch statement is saying. Only you can debug your code...not us, we don't have access to your computer, code, nor do we know anything about what it is you are doing.

If you want meaningful help, give us a meaningful error message/stack trace as a good place to start.
David Crow 22-Jan-18 16:05pm    
Catching Exception is rather generic. What possible exception(s) can be thrown by the three statements in the try block? At the very least, I'd be inclined to look at e.getClass().getName() to help narrow down the problem. Have you used the debugger to step into the getDefault() or sendTextMessage() calls to see what they are doing?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900