Android™
Android™
Get JSON Details from the Last Operation
See more MIME Examples
Demonstrates GetLastJsonData, which copies structured details from the most recent operation into a JsonObject when such details are available. Many operations produce no JSON data, in which case the object is empty or minimal.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.
Background. Some Chilkat operations expose extra diagnostic or result information as JSON. GetLastJsonData provides access to that information after the operation completes.
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;
CkMime mime = new CkMime();
success = mime.LoadMimeFile("qa_data/encrypted.eml");
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
// Some operations produce structured JSON details. After an operation, copy those details into a
// JsonObject with GetLastJsonData. Many methods produce no JSON, in which case the object is
// little or empty.
String pfxPassword = "myPfxPassword";
success = mime.AddPfxSourceFile("qa_data/recipient.pfx",pfxPassword);
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
success = mime.Decrypt();
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
CkJsonObject json = new CkJsonObject();
mime.GetLastJsonData(json);
json.put_EmitCompact(false);
String jsonStr = json.emit();
Log.i(TAG, jsonStr);
}
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."
}
}