Android™
Android™
Dropbox: Get Space Usage
See more Dropbox Examples
Demonstrates how to get the Dropbox space usage information for the current user's account.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 requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkRest rest = new CkRest();
// Connect to the www.dropbox.com endpoint.
boolean bTls = true;
int port = 443;
boolean bAutoReconnect = true;
success = rest.Connect("api.dropboxapi.com",port,bTls,bAutoReconnect);
if (success != true) {
Log.i(TAG, rest.lastErrorText());
return;
}
rest.AddHeader("Authorization","Bearer DROPBOX-ACCESS-TOKEN");
String responseStr = rest.fullRequestNoBody("POST","/2/users/get_space_usage");
if (rest.get_LastMethodSuccess() != true) {
Log.i(TAG, rest.lastErrorText());
return;
}
// Success is indicated by a 200 response status code.
if (rest.get_ResponseStatusCode() != 200) {
// Examine the request/response to see what happened.
Log.i(TAG, "response status code = " + String.valueOf(rest.get_ResponseStatusCode()));
Log.i(TAG, "response status text = " + rest.responseStatusText());
Log.i(TAG, "response header: " + rest.responseHeader());
Log.i(TAG, "response body (if any): " + responseStr);
Log.i(TAG, "---");
Log.i(TAG, "LastRequestStartLine: " + rest.lastRequestStartLine());
Log.i(TAG, "LastRequestHeader: " + rest.lastRequestHeader());
return;
}
CkJsonObject jsonResponse = new CkJsonObject();
jsonResponse.Load(responseStr);
jsonResponse.put_EmitCompact(false);
Log.i(TAG, jsonResponse.emit());
// {
// "used": 3032115,
// "allocation": {
// ".tag": "individual",
// "allocated": 2147483648
// }
// }
//
}
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."
}
}