Android™ Requires Chilkat v11.7.0+
Android™
Generate a QR Code with the Barcode Method
See more QR Code Examples
Demonstrates the Barcode method, which is the general form of QrCode: the request names the symbology, and everything else is the same. QrCode is Barcode with the symbology already set to qr, and identical requests to the two methods give identical results. A program that will produce more than one kind of barcode can use Barcode for all of them.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.
CkJsonObject json = new CkJsonObject();
json.UpdateString("symbology","qr");
json.UpdateString("payload.text","https://www.chilkatsoft.com/");
json.UpdateString("output.path","qa_output/qr_from_barcode.png");
json.UpdateBool("output.overwrite",true);
json.UpdateString("output.return","none");
CkFormats fmt = new CkFormats();
CkJsonObject jsonOut = new CkJsonObject();
success = fmt.Barcode("generate",json,jsonOut);
if (success == false) {
Log.i(TAG, fmt.lastErrorText());
return;
}
Log.i(TAG, "symbology: " + jsonOut.stringOf("symbols[0].symbology"));
Log.i(TAG, "QR version: " + String.valueOf(jsonOut.IntOf("symbols[0].selectedEncoding.version")));
Log.i(TAG, "image: " + String.valueOf(jsonOut.IntOf("outputs[0].width")) + " x " + String.valueOf(jsonOut.IntOf("outputs[0].height")) + " pixels");
// The image written to qa_output/qr_from_barcode.png:
//
// Barcode requires the symbology. QrCode does not.
CkJsonObject json2 = new CkJsonObject();
json2.UpdateString("payload.text","https://www.chilkatsoft.com/");
success = fmt.Barcode("generate",json2,jsonOut);
if (success == false) {
Log.i(TAG, "without a symbology: " + jsonOut.stringOf("errors[0].code") + " at " + jsonOut.stringOf("errors[0].path"));
}
// Sample output:
// symbology: qr
// QR version: 3
// image: 148 x 148 pixels
// without a symbology: missingOption at /symbology
}
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."
}
}