Android™
Android™
SMSAPI - Get User Account Information
See more SMSAPI Examples
Get a list of subusers.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;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
// Implements the following CURL command:
// curl -i -H "Authorization: Bearer token_api_oauth" \
// -H "Content-Type: application/json" -X GET https://api.smsapi.com/subusers
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Adds the "Authorization: Bearer token_api_oauth" header.
http.put_AuthToken("token_api_oauth");
http.SetRequestHeader("Content-Type","application/json");
CkStringBuilder sbResponseBody = new CkStringBuilder();
success = http.QuickGetSb("https://api.smsapi.com/subusers",sbResponseBody);
if (success == false) {
Log.i(TAG, http.lastErrorText());
return;
}
CkJsonArray jarrResp = new CkJsonArray();
jarrResp.LoadSb(sbResponseBody);
jarrResp.put_EmitCompact(false);
Log.i(TAG, "Response Body:");
Log.i(TAG, jarrResp.emit());
int respStatusCode = http.get_LastStatus();
Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
if (respStatusCode >= 400) {
Log.i(TAG, "Response Header:");
Log.i(TAG, http.lastHeader());
Log.i(TAG, "Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// [
// {
// "id": "5A5359173738303F2F95B7E2",
// "username": "subuser1",
// "active": "true",
// "description": "null",
// "from_account": "10.0000",
// "per_month": "0"
// },
// {
// "id": "5A5359173738303F2F95B7E2",
// "username": "subuser2",
// "active": "true",
// "description": "null",
// "from_account": "10.0000",
// "per_month": "0"
// }
// ]
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
CkJsonObject json;
String id;
String username;
String active;
String description;
String from_account;
String per_month;
int i = 0;
int count_i = jarrResp.get_Size();
while (i < count_i) {
json = jarrResp.ObjectAt(i);
id = json.stringOf("id");
username = json.stringOf("username");
active = json.stringOf("active");
description = json.stringOf("description");
from_account = json.stringOf("from_account");
per_month = json.stringOf("per_month");
i = i + 1;
}
}
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."
}
}