Question

I'm trying to send a text message and my code ain't working. Can anyone help me out with that? I tried using code given in tutorials point but its not working.

protected void sendSMSMessage() { 
    Log.i("Send SMS", ""); 
    String phoneNo = txtphoneNo.getText().toString(); 
    String message = txtMessage.getText().toString(); 
    try { 
       SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNo,null,message,null,null); 
        Toast.makeText(getApplicationContext(), "SMS sent.",Toast.LENGTH_LONG).show(); 
    } catch (Exception e) {  
        Toast.makeText(getApplicationContext(),"SMS faild.",Toast.LENGTH_LONG).show(); e.printStackTrace(); } 
    } 
Was it helpful?

Solution

Try like this:

private void sendSMS(String phoneNumber, String message)
{
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, null, null);
}

Also check this Sending a SMS Message from an Android Application

OTHER TIPS

It's SMSManager.sendTextMessage. Remember to request permission in your manifest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top