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)