Sample code for 30+ languages & platforms
Android™

WhatsApp - Download/Retrieve Media

Demonstrates how to download media previously uploaded to the WhatsApp Business API client

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;

    //  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 -X GET \
    //    https://your-webapp-hostname:your-webapp-port/v1/media/4b5bf27b-8672-4d55-bc21-d096dc200d0f \
    //    -H 'Authorization: Bearer your-auth-token' \
    //    -o path/filename

    //  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 your-auth-token" header.
    http.put_AuthToken("your-auth-token");

    CkBinData bdResponseBody = new CkBinData();
    success = http.QuickGetBd("https://your-webapp-hostname:your-webapp-port/v1/media/4b5bf27b-8672-4d55-bc21-d096dc200d0f",bdResponseBody);
    if (success == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    int respStatusCode = http.get_LastStatus();
    Log.i(TAG, "response status code = " + String.valueOf(respStatusCode));
    Log.i(TAG, "response header = " + http.lastResponseHeader());

    if (respStatusCode != 200) {
        Log.i(TAG, "Error response body:");
        Log.i(TAG, bdResponseBody.getString("utf-8"));
        return;
        }

    success = bdResponseBody.WriteFile("path/filename");

  }

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