Allu Allu - 1 year ago 120
Android Question

How to send SMS using Twilio in my android application?

In my android application I have created one button, when I had pressed on the button I want to send message.So for that I have created one java class and written twilio code.

final TwilioRestClient client = new TwilioRestClient(

// Get the main account (The one we used to authenticate the
// client)
final Account mainAccount = client.getAccount();

final SmsFactory messageFactory = mainAccount.getSmsFactory();
final Map<String, String> messageParams = new HashMap<String, String>();
messageParams.put("To", "+912342423423");
messageParams.put("From", "+132432432434");
messageParams.put("Body", "This is my message");
try {
} catch (TwilioRestException e) {

when I am using the above code it showing some error like
java.lang.NoSuchMethodError: org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager

I have added only one jar file in lib folder as
" twilio-java-sdk-3.3.10-jar-with-dependencies.jar ".

please tell me what can I do?

Answer Source

I have used HttpPost method to send sms in that i have passed my url with base authentication here is my code

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost(
        String base64EncodedCredentials = "Basic "
                            + Base64.encodeToString(
                                    (ACCOUNT_SID + ":" + AUTH_TOKEN).getBytes(),

                    try {

                        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                        nameValuePairs.add(new BasicNameValuePair("From",
                        nameValuePairs.add(new BasicNameValuePair("To",
                        nameValuePairs.add(new BasicNameValuePair("Body",
                                "Welcome to Twilio"));

                        httppost.setEntity(new UrlEncodedFormEntity(

                        // Execute HTTP Post Request
                        HttpResponse response = httpclient.execute(httppost);
                        HttpEntity entity = response.getEntity();
                        System.out.println("Entity post is: "
                                + EntityUtils.toString(entity));

                    } catch (ClientProtocolException e) {

                    } catch (IOException e) {


It is working well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download