Read complete story

Send SMS using Twilio in android application

So many times we need to send the SMS or OTP(One time password ) to the user mobile number through our application it can be for any purpose like verification your account , message etc and Twilio make this task more easy for us. Today i am going to share the code for  send sms using twilio.

Twilio is a cloud communications platforms it makes sending and receiving SMS easy, it works as an SMS provider which will send a password to users that attempt to login with a properly configured security policy. You can integrate Twilio SMS service in your application for sending OTP SMS to authenticate the users.

For this process first  thing we need to do is Sign up for a twilio account and we will get –

1. Twillio Account SID
2. Auth token
3. Twilio phone number

Now for the reference i have  added some code with retrofit-

Add the  retrofit dependency  in build.greadle file

we will create a interface for twilio api .

In the above code  ACCOUNT_SID is Twillio Account SID and Authorization is basic Authentication which is base64 of account sid and auth token.

To send sms i have passed the url with base authentication here is the code

In the above code the smsData contain these perameters-

From – the number from you want to send sms.
To –  the number to which you want to send sms
Body – Message you want to send.

If your twilio account is trial account you have to add the test mobile number to the twillio account.

REFERENCE

you can also refer  their integration guide –

https://www.twilio.com/docs/sms

Hope it will help you Thanks for reading.

. . .

Comment (1)

Add Your Comment

  • Ayetolu Samuel
    Thanks for the tutorial,
    Please am getting BAD REQUEST…
    How can i rectify this…
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close