Sample code for 30+ languages & platforms
Android™

Setting a HTTP Max Response Size

Demonstrates the MaxResponseSize property.

Chilkat Android™ Downloads

Android™
// 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();

    int maxSz = 16384;
    http.put_MaxResponseSize(maxSz);

    //  Try to get something larger, such as hamlet.xml which is 279658 bytes
    String xmlStr = http.quickGetStr("https://chilkatsoft.com/hamlet.xml");
    if (http.get_LastMethodSuccess() == false) {
        //  If the LastErrorText contains the string "MaxResponseSize",
        //  then the HTTP request failed because the response body would've been larger than the max allowed response size.
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, "OK");

  }

  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."
  }
}