Android™ Requires Chilkat v11.7.0+
Android™
QR Code Numeric, Alphanumeric and Byte Modes
See more QR Code Examples
Demonstrates the QR encoding modes. Digits alone are stored in numeric mode, and text made only of digits, upper-case letters, space and $ % * + - . / : in alphanumeric mode. Both pack more characters into a symbol than byte mode, which is used for everything else. QrCode chooses the most compact mode the text allows, and the response reports it. A product code written in upper case therefore gives a smaller symbol than the same code in lower case.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.
CkFormats fmt = new CkFormats();
CkJsonObject json = new CkJsonObject();
CkJsonObject jsonOut = new CkJsonObject();
// Digits only.
json.UpdateString("payload.text","00123456789012345678");
success = fmt.QrCode("generate",json,jsonOut);
if (success == false) {
Log.i(TAG, fmt.lastErrorText());
return;
}
Log.i(TAG, "digits: mode " + jsonOut.stringOf("symbols[0].selectedEncoding.mode") + ", version " + String.valueOf(jsonOut.IntOf("symbols[0].selectedEncoding.version")));
// Upper-case letters, digits, space and - are all in the alphanumeric set.
json.UpdateString("payload.text","ORDER-12345 LOT A7 SHELF 12-C");
success = fmt.QrCode("generate",json,jsonOut);
if (success == false) {
Log.i(TAG, fmt.lastErrorText());
return;
}
Log.i(TAG, "upper case: mode " + jsonOut.stringOf("symbols[0].selectedEncoding.mode") + ", version " + String.valueOf(jsonOut.IntOf("symbols[0].selectedEncoding.version")));
// Lower-case letters are not, so the same text in lower case needs byte mode.
json.UpdateString("payload.text","order-12345 lot a7 shelf 12-c");
success = fmt.QrCode("generate",json,jsonOut);
if (success == false) {
Log.i(TAG, fmt.lastErrorText());
return;
}
Log.i(TAG, "lower case: mode " + jsonOut.stringOf("symbols[0].selectedEncoding.mode") + ", version " + String.valueOf(jsonOut.IntOf("symbols[0].selectedEncoding.version")));
// The mode can be named. Byte mode can hold any text. Naming a mode the text cannot use
// (numeric for text with letters, for example) fails with conflictingOptions.
json.UpdateString("payload.text","00123456789012345678");
json.UpdateString("encoding.qr.mode","byte");
success = fmt.QrCode("generate",json,jsonOut);
if (success == false) {
Log.i(TAG, fmt.lastErrorText());
return;
}
Log.i(TAG, "digits as bytes: mode " + jsonOut.stringOf("symbols[0].selectedEncoding.mode") + ", version " + String.valueOf(jsonOut.IntOf("symbols[0].selectedEncoding.version")));
// The four symbols, in the order they were made:
//
// Sample output:
// digits: mode numeric, version 1
// upper case: mode alphanumeric, version 2
// lower case: mode byte, version 3
// digits as bytes: mode byte, version 2
}
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."
}
}