【问题标题】:hotspot or wifi qr code genrate using zxing使用 zxing 生成热点或 wifi 二维码
【发布时间】:2020-05-09 19:53:02
【问题描述】:

如何为我的热点生成一个二维码(我有一个文件,它使用随机 ssid、密码创建热点) 现在我想用zxing为它创建一个二维码。身份验证 = wap/wap2。我还遇到了 thissite 的 api,但它用于 html 文件<img src="https://qrcode.tec-it.com/API/QRCode?data=WIFI%3aT%3aWPA%3bS%3assid%3bP%3apaasword%3b%3b&backcolor=%23ffffff" />,如果可以从 java 文件中获取 ssid 和密码到这个 html 文件,那就太好了,很容易请分享一个 html 代码。或者我们可以使用 zxing 请帮我修改此代码以创建 Authentication= wap/wap2 的二维码。 请帮助我真的需要你的宝贵答案

package javaapplication27;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class NewClass1{
        private static final String qcip = "C:\\Users\\lenovo\\Desktop\\kamal\\qrcode.png";
  private static void generateQRCode(String text, int width, int height, String filePath)
            throws Exception {
        QRCodeWriter qcwobj = new QRCodeWriter();
        BitMatrix bmobj = qcwobj.encode(text, BarcodeFormat.QR_CODE, width, height);
        Path pobj = FileSystems.getDefault().getPath(filePath);
        MatrixToImageWriter.writeToPath(bmobj, "PNG", pobj);
    }
    public static void main(String[] args) {
        try {
            generateQRCode("My Name Is Kamalpreet singh",1250, 1250, qcip);
        } catch (Exception e) {
            System.out.println("Could not generate QR Code" + e);
        } 

    }

【问题讨论】:

标签: android html android-studio android-fragments zxing


【解决方案1】:

如 ZXing 的Github 页面中所述,为了创建 WI-FI 二维码,以便其他设备可以读取该代码并自动连接到 WI-FI,您需要使用以下内容对字符串进行编码结构WIFI:T:WPA;S:mynetwork;P:mypass;; 其中:

  • T:WPA 是在这种情况下设置为 WPA 的身份验证类型;
  • S:mynetwork 是网络 SSID,在本例中设置为 mynetwork;
  • P:mypass 是本例中设置为 mypass 的网络密码;

例如,假设您要为网络生成具有以下特征的二维码:

  • SSID:我的家庭网络
  • 身份验证类型:WPA
  • 密码:ThisIsMyTopSecretPassword

为此,您可以使用以下代码:

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;

public static void main( String[] args ) throws WriterException, IOException {
    QRCodeWriter writer = new QRCodeWriter();
    BitMatrix bitMatrix = writer.encode("WIFI:T:WPA;S:My Home Network;P:ThisIsMyTopSecretPassword;;", BarcodeFormat.QR_CODE, 1920, 1080);

    Path path = FileSystems.getDefault().getPath("C:/Users/user/Desktop/image.png");
    MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
}

这将为前面提到的网络生成宽度为 1920 像素、高度为 1080 像素的二维码,并将该二维码作为 PNG 格式的图像存储在用户“用户”的桌面中。

虽然来晚了,但还是希望对以后的读者有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多