![]() |
VOOZH | about |
QR codes are used in many apps to display data in machine-readable form. These codes are used to represent data in a secure manner that is readable only by machines and not by humans. We have seen many apps that provide QR codes and we can scan those QR codes with our mobile device. In this article, we will take a look at how we can generate a QR Code for our app. So to implement this feature, we will be using a library from GitHub.
Note: You may also refer to How to Read QR Code in Android?
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
- Navigate to the Gradle Scripts > build.gradle.kts (Module:app) and add the below dependency in the dependencies section.
dependencies {
...
implementation ("com.journeyapps:zxing-android-embedded:4.3.0")
}Refer to the following link for the documentation:Click Here
- Navigate to the Gradle Scripts > settings.gradle.kts and add the below line of code in the repositories section.
dependencyResolutionManagement {
...
repositories {
...
mavenCentral()
}
}Now sync the project from the top right corner option of Sync now.
Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.
activity_main.xml:
Go to the MainActivity file and refer to the following code. Below is the code for the MainActivity file. Comments are added inside the code to understand the code in more detail.
Refer to the following github repo to get the entire code: Generate-QR-Code-in-Android