Android™ Requires Chilkat v11.0.0+
Android™
Clickatell One API: Look up SMS delivery status
See more Clickatell Examples
Use the apiMessageId returned by the One API send example and the same integration key. The ID goes in the URL path. The SMS result contains sms.status and the timestamp of the last status change. For example, QUEUED means processing is pending and DEVICE_ACK indicates a device acknowledgment.
The response can also contain a WhatsApp result or have no identifiable channel for an unknown message. For ongoing delivery updates, configure delivery notifications in the integration. This example performs one lookup.
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.
CkHttp http = new CkHttp();
http.put_RequireSslCertVerify(true);
// Supply the key for this One API integration from application configuration.
http.SetRequestHeader("Authorization","ONE_API_KEY");
http.SetRequestHeader("Accept","application/json");
// Use the provider-generated ID from an accepted One API send.
http.SetUrlVar("id","ONE_API_MESSAGE_ID");
CkHttpResponse resp = new CkHttpResponse();
success = http.HttpNoBody("GET","https://platform.clickatell.com/v1/message/{$id}",resp);
if (resp.get_StatusCode() == 0) {
Log.i(TAG, "No HTTP response. Check the connection and retry the lookup.");
return;
}
CkJsonObject reply = new CkJsonObject();
boolean parsed = reply.Load(resp.bodyStr());
if ((success != true) or ((resp.get_StatusCode() != 200))) {
Log.i(TAG, "Clickatell returned HTTP " + String.valueOf(resp.get_StatusCode()));
if (parsed == true) {
if (reply.HasMember("error.description") == true) {
Log.i(TAG, reply.stringOf("error.description"));
}
}
return;
}
if (parsed != true) {
Log.i(TAG, "Expected a JSON response.");
return;
}
// A known SMS has a string status under the sms member.
if (reply.JsonTypeOf("sms.status") != 1) {
if (reply.JsonTypeOf("whatsapp.status") == 1) {
Log.i(TAG, "This message has WhatsApp status: " + reply.stringOf("whatsapp.status"));
}
else {
Log.i(TAG, "No SMS status was returned. Check the message ID and integration.");
if (reply.JsonTypeOf("status") == 1) {
Log.i(TAG, "Reported status: " + reply.stringOf("status"));
}
}
return;
}
Log.i(TAG, "SMS status: " + reply.stringOf("sms.status"));
if (reply.JsonTypeOf("sms.timestamp") == 2) {
// Read the provider timestamp as text to preserve every digit.
Log.i(TAG, "Last status change (provider timestamp): " + reply.stringOf("sms.timestamp"));
}
}
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."
}
}