Sample code for 30+ languages & platforms
Android™

Activix CRM Upload a Recording

See more Activix CRM Examples

Upload a recording for an existing communication.

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 requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpRequest req = new CkHttpRequest();

    req.put_HttpVerb("POST");
    req.put_Path("/api/v2/communications/COMMUNICATION_ID/recording");
    req.put_ContentType("multipart/form-data");

    req.AddHeader("Accept","application/json");

    String pathToFileOnDisk = "qa_data/CantinaBand3.wav";
    success = req.AddFileForUpload("recording",pathToFileOnDisk);
    if (success == false) {
        Log.i(TAG, req.lastErrorText());
        return;
        }

    CkHttp http = new CkHttp();
    http.put_AuthToken("ACCESS_TOKEN");

    CkHttpResponse resp = new CkHttpResponse();
    success = http.HttpSReq("crm.activix.ca",443,true,req,resp);
    if (success == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, "Response Status Code: " + String.valueOf(resp.get_StatusCode()));

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.Load(resp.bodyStr());
    jsonResponse.put_EmitCompact(false);
    Log.i(TAG, jsonResponse.emit());

    if (resp.get_StatusCode() >= 300) {
        Log.i(TAG, "Failed.");
        return;
        }

    // Sample output...

    // {
    //   "message": "Recording uploaded successfully."
    // }
    // 

  }

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