Sample code for 30+ languages & platforms
PureBasic Requires Chilkat v11.7.0+

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 PureBasic Downloads

PureBasic
IncludeFile "CkFormats.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  This example requires the Chilkat API to have been previously unlocked.
    ;  See Global Unlock Sample for sample code.

    fmt.i = CkFormats::ckCreate()
    If fmt.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    jsonOut.i = CkJsonObject::ckCreate()
    If jsonOut.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateInt(json,"render.moduleSize",6)
    CkJsonObject::ckUpdateBool(json,"output.overwrite",1)
    CkJsonObject::ckUpdateString(json,"output.return","none")

    ;  An email, with the address and optionally a subject.  Spaces in the subject are written %20.
    CkJsonObject::ckUpdateString(json,"payload.text","mailto:support@example.com?subject=Order%2012345")
    CkJsonObject::ckUpdateString(json,"output.path","qa_output/qr_email.png")
    success = CkFormats::ckQrCode(fmt,"generate",json,jsonOut)
    If success = 0
        Debug CkFormats::ckLastErrorText(fmt)
        CkFormats::ckDispose(fmt)
        CkJsonObject::ckDispose(json)
        CkJsonObject::ckDispose(jsonOut)
        ProcedureReturn
    EndIf

    Debug "email: version " + Str(CkJsonObject::ckIntOf(jsonOut,"symbols[0].selectedEncoding.version")) + ", " + CkJsonObject::ckStringOf(jsonOut,"outputs[0].path")

    ;  image

    ;  A phone number to dial, in international form.
    CkJsonObject::ckUpdateString(json,"payload.text","tel:+15555550100")
    CkJsonObject::ckUpdateString(json,"output.path","qa_output/qr_phone.png")
    success = CkFormats::ckQrCode(fmt,"generate",json,jsonOut)
    If success = 0
        Debug CkFormats::ckLastErrorText(fmt)
        CkFormats::ckDispose(fmt)
        CkJsonObject::ckDispose(json)
        CkJsonObject::ckDispose(jsonOut)
        ProcedureReturn
    EndIf

    Debug "phone: version " + Str(CkJsonObject::ckIntOf(jsonOut,"symbols[0].selectedEncoding.version")) + ", " + CkJsonObject::ckStringOf(jsonOut,"outputs[0].path")

    ;  image

    ;  A text message: the number, then the message.
    CkJsonObject::ckUpdateString(json,"payload.text","SMSTO:+15555550100:Please call me back")
    CkJsonObject::ckUpdateString(json,"output.path","qa_output/qr_sms.png")
    success = CkFormats::ckQrCode(fmt,"generate",json,jsonOut)
    If success = 0
        Debug CkFormats::ckLastErrorText(fmt)
        CkFormats::ckDispose(fmt)
        CkJsonObject::ckDispose(json)
        CkJsonObject::ckDispose(jsonOut)
        ProcedureReturn
    EndIf

    Debug "sms: version " + Str(CkJsonObject::ckIntOf(jsonOut,"symbols[0].selectedEncoding.version")) + ", " + CkJsonObject::ckStringOf(jsonOut,"outputs[0].path")

    ;  image

    ;  A location: latitude, then longitude, in degrees.
    CkJsonObject::ckUpdateString(json,"payload.text","geo:41.8781,-87.6298")
    CkJsonObject::ckUpdateString(json,"output.path","qa_output/qr_location.png")
    success = CkFormats::ckQrCode(fmt,"generate",json,jsonOut)
    If success = 0
        Debug CkFormats::ckLastErrorText(fmt)
        CkFormats::ckDispose(fmt)
        CkJsonObject::ckDispose(json)
        CkJsonObject::ckDispose(jsonOut)
        ProcedureReturn
    EndIf

    Debug "location: version " + Str(CkJsonObject::ckIntOf(jsonOut,"symbols[0].selectedEncoding.version")) + ", " + CkJsonObject::ckStringOf(jsonOut,"outputs[0].path")

    ;  image

    ;  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


    CkFormats::ckDispose(fmt)
    CkJsonObject::ckDispose(json)
    CkJsonObject::ckDispose(jsonOut)


    ProcedureReturn
EndProcedure