Android Generate Qrcode With ZXing (Kotlin)

Jun 30, 2019

Dependencies.

dependencies {
    implementation 'com.google.zxing:core:3.4.0'
}

Generate QR Code

val content = "bitcoin:3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy"val writer = QRCodeWriter()val bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512)val width = bitMatrix.widthval height = bitMatrix.heightval bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)for (x in 0 until width) {    for (y in 0 until height) {        bitmap.setPixel(x, y, if (bitMatrix.get(x, y)) Color.BLACK else Color.WHITE)    }}imageView.setImageBitmap(bitmap)

zxing-android-embedded

If you are using zxing-android-embedded to scan QR code.

dependencies {
    implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
}
val barcodeEncoder = BarcodeEncoder()val bitmap = barcodeEncoder.encodeBitmap(content, BarcodeFormat.QR_CODE, 512, 512)qrcodeImageView.setImageBitmap(bitmap)

QRGen

https://github.com/kenglxn/QRGen

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.