Sample code for 30+ languages & platforms
Android™

Get JSON Details from the Last PFX Operation

See more PFX/P12 Examples

Demonstrates Pfx.GetLastJsonData, which replaces the contents of a JsonObject with structured JSON information from the most recent operation.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path 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. The data is copied as a complete replacement and is never merged with existing members. The exact members depend on the operation that produced them.

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;

    CkPfx pfx = new CkPfx();

    //  The file path is relative to the application's current working directory.  An absolute path
    //  may also be used.  Supply the path appropriate to your own environment.
    //  The PFX password should come from a secure source rather than being hard-coded.
    String password = "myPfxPassword";
    success = pfx.LoadPfxFile("qa_data/identity.pfx",password);
    if (success == false) {
        Log.i(TAG, pfx.lastErrorText());
        return;
        }

    //  Copy structured JSON information from the most recent operation into a JsonObject.  The contents
    //  entirely replace anything already in the object.
    CkJsonObject json = new CkJsonObject();
    pfx.GetLastJsonData(json);

    json.put_EmitCompact(false);
    String jsonStr = json.emit();
    Log.i(TAG, jsonStr);
    //  JSON parsing code for this result can be generated at Chilkat's online tool:
    //  https://tools.chilkat.io/jsonParse

  }

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