Android™
Android™
Example: Http.QuickGetSb method
Demonstrates theQuickGetSb method.
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;
CkHttp http = new CkHttp();
// Send the HTTP GET and return the content in a StringBuilder
CkStringBuilder sb = new CkStringBuilder();
success = http.QuickGetSb("https://www.chilkatsoft.com/helloWorld.json",sb);
if (http.get_LastMethodSuccess() == false) {
if (http.get_LastStatus() == 0) {
// Communications error. We did not get a response.
Log.i(TAG, http.lastErrorText());
}
else {
Log.i(TAG, "Response status code: " + String.valueOf(http.get_LastStatus()));
Log.i(TAG, "Response body error text:");
Log.i(TAG, sb.getAsString());
}
return;
}
// The downloaded content:
Log.i(TAG, sb.getAsString());
Log.i(TAG, "Success");
}
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."
}
}