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

Create a Wi-Fi QR Code

See more QR Code Examples

Demonstrates a QR code that joins a phone to a Wi-Fi network when scanned. A QR code only holds text. Phones recognize text of the form WIFI:T:;S:;P:;; and offer to join the network. T is WPA (also used for WPA2 and WPA3), WEP, or nopass for an open network, and H:true can be added for a hidden network. In the name and the password, the characters backslash, semicolon, comma, colon and double quote must each be preceded by a backslash.

Chilkat Android™ Downloads

Android™
// 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("payload.text","WIFI:T:WPA;S:Chilkat Guest;P:correct-horse-battery-staple;;");

    //  Level Q, so that the code still scans when it is printed small or gets worn.
    json.UpdateString("encoding.qr.errorCorrection","Q");
    json.UpdateInt("render.moduleSize",8);

    //  Say which network it is under the code.
    json.UpdateBool("render.text.enabled",true);
    json.UpdateString("render.text.value","Wi-Fi: Chilkat Guest");
    json.UpdateInt("render.text.scale",2);

    json.UpdateString("output.path","qa_output/qr_wifi.png");
    json.UpdateBool("output.overwrite",true);
    json.UpdateString("output.return","none");

    CkFormats fmt = new CkFormats();
    CkJsonObject jsonOut = new CkJsonObject();
    success = fmt.QrCode("generate",json,jsonOut);
    if (success == false) {
        Log.i(TAG, fmt.lastErrorText());
        return;
        }

    Log.i(TAG, "file: " + jsonOut.stringOf("outputs[0].path"));
    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_wifi.png:

    //  image

    //  Sample output:

    //  file: qa_output/qr_wifi.png
    //  QR version: 5
    //  image: 360 x 374 pixels

  }

  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."
  }
}