0

I have tried this code but I did not receive SMS in my phone.

    Intent intent=new Intent(getApplicationContext(),MainActivity.class);  
    PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);  

    //Get the SmsManager instance and call the sendTextMessage method to send message                 
    SmsManager sms=SmsManager.getDefault();  
    sms.sendTextMessage("88xxxxxxx0", null, "hello javatpoint", pi,null);
Diego Malone
  • 1,044
  • 9
  • 25

1 Answers1

0

You can send message from your application through this:

public void sendSMS(String MoNo, String msg) {
    try {      
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(MoNo, null, msg, null, null);    
        Toast.makeText(getApplicationContext(), "Message Sent",
              Toast.LENGTH_LONG).show();
    } catch (Exception ex) {
        Toast.makeText(getApplicationContext(),ex.getMessage().toString(),
              Toast.LENGTH_LONG).show();
        ex.printStackTrace();
    } 
}

Also you need to give SEND_SMS permission in AndroidManifest.xml to send message

<uses-permission android:name="android.permission.SEND_SMS" />

Thanks. Happy Coding...

Mayur
  • 735
  • 4
  • 14