skip to Main Content

I am Using the Below Code ….But The SMS Does not Come…

private void sendSms(String toPhoneNumber, String message){
        OkHttpClient client = new OkHttpClient();
        String ACCOUNT_SID="XXXXXXXXXXXXXXXXXXXXXXXXXX";
        String AUTH_TOKEN="XFAXXXXXXXXXXXXXXXXXXXXXXXXX";
        String url = "https://api.twilio.com/2010-04-01/Accounts/"+ACCOUNT_SID+"/SMS/Messages";
        String base64EncodedCredentials = "Basic " + Base64.encodeToString((ACCOUNT_SID + ":" + AUTH_TOKEN).getBytes(), Base64.NO_WRAP);

        RequestBody body = new FormBody.Builder()
                .add("From", "+16463525791")
                .add("To", toPhoneNumber)
                .add("Body", message)
                .build();

        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .header("Authorization", base64EncodedCredentials)
                .build();
        try {
            Response response = client.newCall(request).execute();
           // Log.d(TAG, "sendSms: "+ response.body().string());
        } catch (IOException e) { e.printStackTrace(); }

    }

I need to Send SMS to User After Sign UP…Pls Help….

2

Answers


  1. It’s really easy to send an outgoing SMS using Twilio. To send an SMS, make an HTTP POST request to the Messages resource.

    POST https://api.twilio.com/2010-04-01/Accounts/AC123456abc/Messages
    Our twilio-python helper library makes this extremely easy. add the following lines:

    send_sms.java

    from twilio.rest import TwilioRestClient
    
    account_sid = "ACXXXXXXXXXXXXXXXXX"
    auth_token = "YYYYYYYYYYYYYYYYYY"
    client = TwilioRestClient(account_sid, auth_token)
    
    message = client.messages.create(to="+12316851234", from_="+15555555555",body="Hello there!")
    

    The from_ number must be a valid Twilio phone number. The to number can be any outgoing number.

    If you are using a Twilio Trial account for this example, you will only be able to send SMS messages to phone numbers that you have verified with Twilio. Phone numbers can be verified via your Twilio Account’s Phone Numbers Page.
    It’s also easy to send an outgoing MMS using Twilio. To send an MMS, you also make an HTTP POST request to the Messages resource but this time specify one or more MediaUrl parameters.

    MMS messages can only be sent and received by numbers having MMS capability. You can check the capabilities of numbers in the account portal or query the Available Phone Numbers resource to search for Twilio numbers that are MMS enabled.

    message = client.messages.create(to="+12316851234", from_="+15555555555",
                                         body="Hello there!",
                                         media_url=['https://demo.twilio.com/owl.png', 'https://demo.twilio.com/logo.png'])
    

    Note that the body argument is optional if you are sending one or more MediaUrls.

    Login or Signup to reply.
  2. Twilio developer evangelist here.

    First up, we don’t recommend that you make calls to the Twilio API directly from within your Android application. To do this you would expose your account credentials which could lead to them being stolen and used by a malicious attacker.

    The good news is that we have a whole blog post on sending SMS messages from Android by building a server yourself in Java. Check that blog post out here: https://www.twilio.com/blog/2016/05/how-to-send-an-sms-from-android.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search