Java Requires Chilkat v11.7.0+
Chilkat2 Java
QR Codes for Email, Phone, SMS and Location
See more QR Code Examples
Demonstrates QR codes that start an action on a phone. A QR code only holds text, and what happens on scanning depends on the form of that text: mailto: starts an email, tel: dials a number, SMSTO: starts a text message, and geo: opens a map at a latitude and longitude. A web address opens in the browser.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Formats;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Formats fmt = new Formats();
JsonObject json = new JsonObject();
JsonObject jsonOut = new JsonObject();
json.updateInt("render.moduleSize", 6);
json.updateBool("output.overwrite", true);
json.updateString("output.return", "none");
// An email, with the address and optionally a subject. Spaces in the subject are written %20.
json.updateString("payload.text", "mailto:support@example.com?subject=Order%2012345");
json.updateString("output.path", "qa_output/qr_email.png");
try {
fmt.qrCode("generate", json, jsonOut);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("email: version " + jsonOut.intOf("symbols[0].selectedEncoding.version") + ", " + jsonOut.stringOf("outputs[0].path"));
//
// A phone number to dial, in international form.
json.updateString("payload.text", "tel:+15555550100");
json.updateString("output.path", "qa_output/qr_phone.png");
try {
fmt.qrCode("generate", json, jsonOut);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("phone: version " + jsonOut.intOf("symbols[0].selectedEncoding.version") + ", " + jsonOut.stringOf("outputs[0].path"));
//
// A text message: the number, then the message.
json.updateString("payload.text", "SMSTO:+15555550100:Please call me back");
json.updateString("output.path", "qa_output/qr_sms.png");
try {
fmt.qrCode("generate", json, jsonOut);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("sms: version " + jsonOut.intOf("symbols[0].selectedEncoding.version") + ", " + jsonOut.stringOf("outputs[0].path"));
//
// A location: latitude, then longitude, in degrees.
json.updateString("payload.text", "geo:41.8781,-87.6298");
json.updateString("output.path", "qa_output/qr_location.png");
try {
fmt.qrCode("generate", json, jsonOut);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("location: version " + jsonOut.intOf("symbols[0].selectedEncoding.version") + ", " + jsonOut.stringOf("outputs[0].path"));
//
// Sample output:
// email: version 4, qa_output/qr_email.png
// phone: version 2, qa_output/qr_phone.png
// sms: version 3, qa_output/qr_sms.png
// location: version 2, qa_output/qr_location.png
}
}