Android™ Requires Chilkat v11.0.0+
Android™
Check message delivery status with Twilio
See more Twilio Examples
Fetch an outbound SMS or MMS using the Message SID returned by a live send. A queued message is waiting to be sent. A sent message has been accepted by the upstream carrier. Delivered means Twilio received delivery confirmation. Some routes provide no final delivery receipt.
Read the current status once per lookup. For failed or undelivered messages, display the available delivery error code and text for troubleshooting. A missing message or an HTTP authentication error is a separate result from a delivery failure.
Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Load an API key for the Twilio account from private application configuration.
CkHttp http = new CkHttp();
http.put_RequireSslCertVerify(true);
http.put_BasicAuth(true);
http.put_Login("YOUR_API_KEY_SID");
http.put_Password("YOUR_API_KEY_SECRET");
CkStringBuilder url = new CkStringBuilder();
url.Append("https://api.twilio.com/2010-04-01/Accounts/");
url.Append("YOUR_ACCOUNT_SID");
url.Append("/Messages");
url.Append("/");
url.Append("YOUR_MESSAGE_SID");
url.Append(".json");
CkHttpResponse resp = new CkHttpResponse();
CkJsonObject reply = new CkJsonObject();
success = http.HttpNoBody("GET",url.getAsString(),resp);
if (resp.get_StatusCode() == 0) {
Log.i(TAG, "No HTTP response from Twilio.");
return;
}
boolean parsed = reply.Load(resp.bodyStr());
if ((success != true) or (resp.get_StatusCode() != 200)) {
Log.i(TAG, "Twilio returned HTTP " + String.valueOf(resp.get_StatusCode()));
if ((parsed == true) and (reply.JsonTypeOf("code") == 2)) {
Log.i(TAG, "Twilio error: " + String.valueOf(reply.IntOf("code")) + " " + reply.stringOf("message"));
}
return;
}
if (parsed != true) {
Log.i(TAG, "Expected a JSON response from Twilio.");
return;
}
if (reply.JsonTypeOf("status") != 1) {
Log.i(TAG, "Message status missing from response.");
return;
}
Log.i(TAG, "Delivery status: " + reply.stringOf("status"));
if ((reply.StringOfEquals("status","failed",true) == true) or (reply.StringOfEquals("status","undelivered",true) == true)) {
if (reply.JsonTypeOf("error_code") == 2) {
Log.i(TAG, "Delivery error code: " + String.valueOf(reply.IntOf("error_code")));
}
if (reply.JsonTypeOf("error_message") == 1) {
Log.i(TAG, reply.stringOf("error_message"));
}
}
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}