Android™ Requires Chilkat v11.7.0+
Android™
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 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();
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");
success = fmt.QrCode("generate",json,jsonOut);
if (success == false) {
Log.i(TAG, fmt.lastErrorText());
return;
}
Log.i(TAG, "email: version " + String.valueOf(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");
success = fmt.QrCode("generate",json,jsonOut);
if (success == false) {
Log.i(TAG, fmt.lastErrorText());
return;
}
Log.i(TAG, "phone: version " + String.valueOf(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");
success = fmt.QrCode("generate",json,jsonOut);
if (success == false) {
Log.i(TAG, fmt.lastErrorText());
return;
}
Log.i(TAG, "sms: version " + String.valueOf(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");
success = fmt.QrCode("generate",json,jsonOut);
if (success == false) {
Log.i(TAG, fmt.lastErrorText());
return;
}
Log.i(TAG, "location: version " + String.valueOf(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
}
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."
}
}