Search code examples
javaandroidqr-codezxing

Generate Arabic QR Code


In my app I generate a QR name in Arabic and then scan and I use zxing library to generate but it seems that zxing library doesn't support Arabic language because when I scan the generated name it gives me ????. What is the solution?

This is my code to generate:

 BitMatrix bitMatrix = multiFormatWriter.encode(text2QR, BarcodeFormat.QR_CODE, 500, 500);
 BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
 bitmap = barcodeEncoder.createBitmap(bitMatrix);
 imageView = (ImageView) findViewById(R.id.imageView);
 imageView.setImageBitmap(bitmap);

Solution

  • I found solution:

    MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
    Map<EncodeHintType, Object> hintMap = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
    
    hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");
    hintMap.put(EncodeHintType.MARGIN, 1); /* default = 4 */
    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
    
    BitMatrix bitMatrix = multiFormatWriter.encode(text2QR, BarcodeFormat.QR_CODE, 500, 500, hintMap);
    BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
    bitmap = barcodeEncoder.createBitmap(bitMatrix);
    imageView = (ImageView) findViewById(R.id.imageView);
    imageView.setImageBitmap(bitmap);