I have written few posts in the past on Android Barcode scanner and Android QRcode scanner and received a lot of questions from readers about how to use the code in a complete application. So, I have decided to make an end to end application using QRcode scanner.
Before I start, you should know that making a complete application require 40% planning and 60% coding. Let’s start with the planning phase, those who are only interested in code can skip this section.
Planning Section:
In this section we will try to decide:
- what we are making
- what tasks can be done with our application
- how will the user interact with this application
What are we making (Idea behind the app):
My purpose is to create something which is useful and everyone can try it, so I decided to make Aadhaar Card Scanner. Well I know not all of my readers know what Aadhar Card is, so here is a brief introduction.
Aadhaar is a 12 digit individual identification number issued by the Unique Identification Authority of India on behalf of the Government of India. This number will serve as a proof of identity and address, anywhere in India. For more information you can further read on UIDAI Site.
Aadhaar card is the printed version of this information on a paper card. Almost everyone in India has Aadhaar card so this app is useful for everyone in India.
To make Aadhaar card machine readable it has a QRcode which contains card holder’s information. Here is a sample image.
What Tasks can be done with our Aadhaar card scanner (app features):
Below are all the tasks our users can perform with this app:
- User can scan Aadhar card and view the information in the app.
- User can save the information in the app
- User can view the saved Aadhar Card information
- User can delete the saved Aadhar card information
How will user interact with the app (app screens and user experience):
Now that we know all the features of our app, we need to decide the user journey, which means how user will interact with our app and what all screens he will go through. Following is a basic list:
- Home Screen : This is the main screen our user will see when he launch the app. This screen will have two “call to actions” (buttons). One to start a new scan (Scan new Aadhaar Card) and second to view saved Aadhaar cards
- Scan Card Screen : This screen will come when user will click/touch on “Scan new Aadhaar Card” button. This will let the user scan QRcode of Aadhaar card.
- Scanned Aadhaar Card data : This screen will come when a successful scans is done. This screen will show the data scanned from QRcode. User can save the scanned data or cancel and start a new scan.
- Saved Aadharr Card : This screen will come when user clicks/touch on “View Saved Aadhar Card” button from home screen. This screen will list all the saved Aadhar Cards. User can delete the saved Aadhar Cards from here.
Below is a simple flow diagram to understand user journey on our application.
After all the decision making, now we have a clear picture of what we are making and what things will it do. This will decide the scope of our development/coding.
Development Phase :
Before we start anything, I assume readers have basic knowledge of Android application development and how to use Android Studio. Event if you don’t it is not that difficult to follow this post. So lets dive in and create our application.
Open android studio and create your application with a blank activity. We will call this HomeActivity. This will be the starting point of our application. We will use this activity to do following :
- Show the home page.
- Show the scan screen
- Display the scanned data
Home Activity : This is your first activity and by default it comes with an action bar. We do not need this action bar so add the following into your “onCreate” function.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//hide the default action bar
getSupportActionBar().hide();
}
Now we need to create the layout or the front-end of our screen. Below is an image of the layout which we want to create.
The layout is pretty simple. So lets create a new layout file in your resource layout folder (/app/src/main/res/layout/) and name it as activity_home.xml. This fie will create the frontend of our activity.It is a long file so I am not embedding it in this post. However you can view it on my github, please Click to see full source code of activity_home.xml on my github.
The file is well commented to show different sections of the screen. If you will notice near line 128, there is a hidden section marked with comment
<!-- Scanned Data-->
This will be used to display scanned result. There are few onclick function attached to the layout which will control the user interaction. Below is the description of these functions :
scanNow (line 64): this function is attached to “Scan new Aadhaar Card” button and it will initiate the new scan. Function is defined in HomeActivity.java.
public void scanNow( View view){
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt("Scan a Aadharcard QR Code");
integrator.setResultDisplayDuration(500);
integrator.setCameraId(0); // Use a specific camera of the device
integrator.initiateScan();
}
This function will use the ZXing Library to scan QRcode on Aadhaar card. To use this you need to add this library as a dependency in your project and build your project. Open your build.gradle file (located in root app directory) and add the below lines at end of the file:
// Added by raj
repositories {
mavenCentral()
maven {
url "http://dl.bintray.com/journeyapps/maven"
}
}
// Added by raj ends
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
// Added by raj
// Supports Android 4.0.3 and later (API level 15)
compile 'com.journeyapps:zxing-android-embedded:2.0.1@aar'
// Supports Android 2.1 and later (API level 7),
//but not optimal for later Android versions.
// If you only plan on supporting Android 4.0.3 and up,
// you don't need to include this.
compile 'com.journeyapps:zxing-android-legacy:2.0.1@aar'
// Convenience library to launch the scanning and encoding Activities.
// It automatically picks the best scanning library from
// the above two, depending on the
// Android version and what is available.
compile 'com.journeyapps:zxing-android-integration:2.0.1@aar'
// Version 3.0.x of zxing core contains some code that
// is not compatible on Android 2.2 and earlier.
// This mostly affects encoding, but you should test if
// you plan to support these versions.
// Older versions e.g. 2.2 may also work if you need support
// for older Android versions.
compile 'com.google.zxing:core:3.0.1'
// Added by raj ends
}
After updating the gradle file and rebuilding your project the ZXing library will be available and scanNow function will launch the camera which you can use to scan the QRcode. Now we will write the handler function which will receive the result from scan.
onActivityResult (HomeActivity Line:90): this function will receive the result from the scan event. The result will be extracted and passed to another function to process the received string.
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//retrieve scan result
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
//we have a result
String scanContent = scanningResult.getContents();
String scanFormat = scanningResult.getFormatName();
// process received data
processScannedData(scanContent);
}else{
Toast toast = Toast.makeText(getApplicationContext(),"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
processScannedData (Line : 112): This function is used to process the string received from scanning the QRcode. The string is a xml string (that is what Aadhaar system uses). We have declared variables to store the extracted information at the beginning of our activity class.
// variables to store extracted xml data
String uid,name,gender,yearOfBirth,careOf,villageTehsil,postOffice,district,state,postCode;
There are different ways to process xml string and you can select your favourite method. However I am using XmlPullParser. Once the information is extracted we call displayScannedData function which will display the information on screen.
protected void processScannedData(String scanData){
Log.d("Rajdeol",scanData);
XmlPullParserFactory pullParserFactory;
try {
// init the parserfactory
pullParserFactory = XmlPullParserFactory.newInstance();
// get the parser
XmlPullParser parser = pullParserFactory.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(new StringReader(scanData));
// parse the XML
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
Log.d("Rajdeol","Start document");
} else if(eventType == XmlPullParser.START_TAG && DataAttributes.AADHAAR_DATA_TAG.equals(parser.getName())) {
// extract data from tag
//uid
uid = parser.getAttributeValue(null,DataAttributes.AADHAR_UID_ATTR);
//name
name = parser.getAttributeValue(null,DataAttributes.AADHAR_NAME_ATTR);
//gender
gender = parser.getAttributeValue(null,DataAttributes.AADHAR_GENDER_ATTR);
// year of birth
yearOfBirth = parser.getAttributeValue(null,DataAttributes.AADHAR_YOB_ATTR);
// care of
careOf = parser.getAttributeValue(null,DataAttributes.AADHAR_CO_ATTR);
// village Tehsil
villageTehsil = parser.getAttributeValue(null,DataAttributes.AADHAR_VTC_ATTR);
// Post Office
postOffice = parser.getAttributeValue(null,DataAttributes.AADHAR_PO_ATTR);
// district
district = parser.getAttributeValue(null,DataAttributes.AADHAR_DIST_ATTR);
// state
state = parser.getAttributeValue(null,DataAttributes.AADHAR_STATE_ATTR);
// Post Code
postCode = parser.getAttributeValue(null,DataAttributes.AADHAR_PC_ATTR);
} else if(eventType == XmlPullParser.END_TAG) {
Log.d("Rajdeol","End tag "+parser.getName());
} else if(eventType == XmlPullParser.TEXT) {
Log.d("Rajdeol","Text "+parser.getText());
}
// update eventType
eventType = parser.next();
}
// display the data on screen
displayScannedData();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}// EO function
displayScannedData : This function hides the home layout, set the value of all the extracted data to display and finally show the scanned data layout.
public void displayScannedData(){
ll_data_wrapper.setVisibility(View.GONE);
ll_scanned_data_wrapper.setVisibility(View.VISIBLE);
ll_action_button_wrapper.setVisibility(View.VISIBLE);
// clear old values if any
tv_sd_uid.setText("");
tv_sd_name.setText("");
tv_sd_gender.setText("");
tv_sd_yob.setText("");
tv_sd_co.setText("");
tv_sd_vtc.setText("");
tv_sd_po.setText("");
tv_sd_dist.setText("");
tv_sd_state.setText("");
tv_sd_pc.setText("");
// update UI Elements
tv_sd_uid.setText(uid);
tv_sd_name.setText(name);
tv_sd_gender.setText(gender);
tv_sd_yob.setText(yearOfBirth);
tv_sd_co.setText(careOf);
tv_sd_vtc.setText(villageTehsil);
tv_sd_po.setText(postOffice);
tv_sd_dist.setText(district);
tv_sd_state.setText(state);
tv_sd_pc.setText(postCode);
}
The scanned data layout has two call-to-action (buttons) “Save” and “Cancel”. Cancel will call function showHome which will hide the scanned data layout and show the home layout. Save will save the scanned data.
For saving the data we will use device Internal storage and save the information in JSON format. We could have just used xml but JSON is pretty neat and is used widely now days.
To abstract the storage choice and get a flexibility to change storage to whatever I want later I have created a Storage class and defined methods for read, write and check if storage file exists.
You can see the full code of storage class here. I have created a utils folder and added all the supported class files in it.
saveData : this function will save the extracted data from the xml string in the form of JSON into device internal storage. For absolute beginners, I don’t want to hard-code the keys for my JSON so I have created a class DataAttributes and declared all my keys in this class. This will help me easily maintain any spelling changes in the keys. DataAttributes class is added in utils folder and included in HomeActivity.
public void saveData(View view){
// We are going to use json to save our data
// create json object
JSONObject aadhaarData = new JSONObject();
try {
aadhaarData.put(DataAttributes.AADHAR_UID_ATTR, uid);
if(name == null){name = "";}
aadhaarData.put(DataAttributes.AADHAR_NAME_ATTR, name);
if(gender == null){gender = "";}
aadhaarData.put(DataAttributes.AADHAR_GENDER_ATTR, gender);
if(yearOfBirth == null){yearOfBirth = "";}
aadhaarData.put(DataAttributes.AADHAR_YOB_ATTR, yearOfBirth);
if(careOf == null){careOf = "";}
aadhaarData.put(DataAttributes.AADHAR_CO_ATTR, careOf);
if(villageTehsil == null){villageTehsil = "";}
aadhaarData.put(DataAttributes.AADHAR_VTC_ATTR, villageTehsil);
if(postOffice == null){postOffice = "";}
aadhaarData.put(DataAttributes.AADHAR_PO_ATTR, postOffice);
if(district == null){district = "";}
aadhaarData.put(DataAttributes.AADHAR_DIST_ATTR, district);
if(state == null){state = "";}
aadhaarData.put(DataAttributes.AADHAR_STATE_ATTR, state);
if(postCode == null){postCode = "";}
aadhaarData.put(DataAttributes.AADHAR_PC_ATTR, postCode);
// read data from storage
String storageData = storage.readFromFile();
JSONArray storageDataArray;
//check if file is empty
if(storageData.length() > 0){
storageDataArray = new JSONArray(storageData);
}else{
storageDataArray = new JSONArray();
}
// check if storage is empty
if(storageDataArray.length() > 0){
// check if data already exists
for(int i = 0; i<storageDataArray.length();i++){
String dataUid = storageDataArray.getJSONObject(i).getString(DataAttributes.AADHAR_UID_ATTR);
if(uid.equals(dataUid)){
// do not save anything and go back
// show home screen
tv_cancel_action.performClick();
return;
}
}
}
// add the aadhaar data
storageDataArray.put(aadhaarData);
// save the aadhaardata
storage.writeToFile(storageDataArray.toString());
// show home screen
tv_cancel_action.performClick();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
showSavedCards : This function is attached to “View Saved Aadhaar Card” call-to-action(button) on the main home screen and this will launch our second activity which is SavedAadhaarCardActivity.
SavedAadhaarCardActivity : This is our second activity and it will display the saved Aadhaar cards. If there is no saved Aadhaar card it will show a default message and a link to go back to home. Here is the layout :
Below is the layout file code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.rajdeol.aadhaarreader.SavedAadhaarCardActivity">
<LinearLayout
android:id="@+id/ll_saved_card_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:onClick="showHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.actionButton"
android:background="@color/action_save_background"
android:text="@string/label_home"
android:gravity="center|left"/>
<TextView
android:id="@+id/tv_no_saved_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/no_saved_card"
android:visibility="gone"
android:layout_margin="@dimen/no_card_msg_margin"
android:textSize="@dimen/no_card_msg_text_size"/>
</LinearLayout>
<LinearLayout
android:layout_below="@+id/ll_saved_card_message"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/lv_saved_card_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
</RelativeLayout>
I have used ListView to display the list of saved aadhaar cards. The code for adaptor used to bind the data and construct the list is added into a separate class called CardListAdapter this class is added to utils folder code of CardListAdapter can be found here.
onCreate : this function will read the file from storage class and parse the JSON to construct the ListView.
protected void onCreate(Bundle savedInstanceState) {
//hide the default action bar
getSupportActionBar().hide();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_saved_aadhaar_card);
//init UI elements
tv_no_saved_card = (TextView)findViewById(R.id.tv_no_saved_card);
lv_saved_card_list = (ListView)findViewById(R.id.lv_saved_card_list);
// init storage
storage = new Storage(this);
// read data from storage
String storageData = storage.readFromFile();
//check if file is not empty
if(storageData.length() > 0){
try {
// convert JSON string to array
storageDataArray = new JSONArray(storageData);
// handle case of empty JSONArray after delete
if(storageDataArray.length()<1){
// hide list and show message
tv_no_saved_card.setVisibility(View.VISIBLE);
lv_saved_card_list.setVisibility(View.GONE);
//exit
return;
}
// init data list
cardDataList = new <JSONObject>ArrayList();
//prepare the data list for list adapter
for(int i = 0; i<storageDataArray.length();i++){
JSONObject dataObject = storageDataArray.getJSONObject(i);
cardDataList.add(dataObject);
}
// create List Adapter with data
ArrayAdapter<ArrayList> savedCardListAdapter = new CardListAdapter(this,cardDataList);
// populate list
lv_saved_card_list.setAdapter(savedCardListAdapter);
}catch (JSONException e){
e.printStackTrace();
}
}else{
// hide list and show message
tv_no_saved_card.setVisibility(View.VISIBLE);
lv_saved_card_list.setVisibility(View.GONE);
}
}
deleteCard : this function will delete the aadhaar card from saved list.
public void deleteCard(String uid){
// read data from storage
String storageData = storage.readFromFile();
JSONArray storageDataArray;
//check if file is empty
if(storageData.length() > 0){
try {
storageDataArray = new JSONArray(storageData);
// coz I am working on Android version which doesnot support remove method on JSONArray
JSONArray updatedStorageDataArray = new JSONArray();
// check if data already exists
for(int i = 0; i<storageDataArray.length();i++){
String dataUid = storageDataArray.getJSONObject(i).getString(DataAttributes.AADHAR_UID_ATTR);
if(!uid.equals(dataUid)){
updatedStorageDataArray.put(storageDataArray.getJSONObject(i));
}
}
// save the updated list
storage.writeToFile(updatedStorageDataArray.toString());
// Hide the list if all cards are deleted
if(updatedStorageDataArray.length() < 1){
// hide list and show message
tv_no_saved_card.setVisibility(View.VISIBLE);
lv_saved_card_list.setVisibility(View.GONE);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
These were the main functions which are being used in the application. However I have added few more function to navigate between the two activities. I have also added DataAttributes class in Utils folder to manage any change in xml attribute name in future.
This is a simple application which saves scanned data in internal storage and display it on the screen. You can modify the Storage class to save the information in a backend service. Don’t forget to read How to write secure webservices.
The full code for this application can be found on my Github under Android Aadhaar card Scanner.
130 Responses to “Android Aadhaar Card Scanner”
August 29, 2016
saraswati upasehi
can you please tell me how to use this code in fragment.
thanks
December 11, 2016
Rajinder DeolHi Saraswati,
I have written a new post for this please read : https://rajislearning.com/android-barcode-scanner-in-fragment/
December 14, 2016
mohan lamaHow can we insert search bar using code on my aadhar card website.
December 14, 2016
Rajinder DeolHi Mohan,
You can scan the code from the app and then open your site within the app using web view. You can pass the scanned code in the URL of your site.
I have written a detailed post about this, please read https://rajislearning.com/add-android-barcode-scanner-to-your-website/
January 3, 2017
Nikhil NaikThe camera launch is failing on after i run the app through my android phone.
Any help would be appreciated
thank you
January 3, 2017
Nikhil NaikSorry i just figured out that my app din have camera permission on.
The app is working fine.
great app sir
thank you
January 3, 2017
Rajinder DeolThanks Nikhil, let me know if you need any help.
August 29, 2017
Chinmoy DashI am getting Barcode Scanner error .I am getting a dialog box written
“Sorry , the Android Camera encountered a problem .You May need to restart the device ”
This is happening even after I have added these camera permissions and features .
Plz advice
August 30, 2017
Rajinder DeolHi Chinmoy,
are you testing on emulator or on an actual device ?. Also can you share the error log you get in your android studio. Errors are visible in logcat.
August 30, 2017
Chinmoy Dash08-30 08:40:33.310 13286-13470/com.example.chinmoydash.aadhaarcardscanner E/libGLESv2: HWUI Protection: wrong call from hwui context F: ES3-glCreateProgramSEC.
Above Message appears when the app is installed .
Clicking on the “Scan new AAdhar Card ” doesnt give any message on the Android Monitor Window .only the Dialog Box appears with this message .
“Sorry , the Android Camera encountered a problem .You May need to restart the device ”
When I press the ok button on the Dialog box this message appears
“08-30 08:44:57.300 13286-13286/com.example.chinmoydash.aadhaarcardscanner E/ViewRootImpl: sendUserActionEvent() mView == null”
And I am testing these on a Actual device .
these things happen even after the above permission and features have been added .
August 30, 2017
Chinmoy Dashandroid.permission.CAMERA PERMISSION
android.hardware.camera feature have already been added .
Thanks for your response
Waiting for your revert
August 31, 2017
Rajinder DeolLooking at your log there is error in function sendUserActionEvent() while accessing mView. Can you push your code in github and share the link so that I can have a look.
August 31, 2017
Chinmoy DashHi Rajinder .
Well I have added camera features and permissions . Rest is same as your code.
Here is the link to the code on github .
https://github.com/chinmoydash/AadhaarCardScanner/find/master
September 1, 2017
Rajinder DeolI will have a look at get back to you.
September 2, 2017
Rajinder DeolHi Chinmoy,
I have built your app and its working fine on my Samsung Galaxy, also the log you have shared are not relevant to the issue. Can you save your device monitor output(in android studio, right next to logcat) and upload it as a gist( u can create gist on githum) and share the link.
September 3, 2017
Chinmoy DashHi Rajinder here are he links to snapshot of Monitor and logcat .
https://drive.google.com/open?id=0B-Q7EbGAsw_NOGpucGxxallpdzQ
https://drive.google.com/open?id=0B-Q7EbGAsw_NSFJ5Q2ZVTjJsYW8
After clicking scan Aadhaar I get
https://drive.google.com/open?id=0B-Q7EbGAsw_NTTdzcUp4NTR0Rnc
after clicking OK that appears on the above step
I get
https://drive.google.com/open?id=0B-Q7EbGAsw_NcW5aTTJWT25DVTQ
In the meanwhile the view on the monitor does’nt change
September 4, 2017
Rajinder DeolHi Chinmoy,
thanks for sharing the logs, I have done some research and found that this issue is with some samsung devices. Read
https://stackoverflow.com/questions/23016155/senduseractionevent-mview-null-on-samsung-tab3
https://stackoverflow.com/questions/20160737/senduseractionevent-mview-null-after-clicking-on-button
https://stackoverflow.com/questions/18028666/senduseractionevent-is-null
I don’t have a device to reproduce this so you can try the solutions mentioned in the stackoverflow questions and let me know if you were able to fix it. Let me know if you need more help.
January 16, 2018
GAJANANDHOW TO MAKE ITEXT PDF FONT IN HINDI NOT DISPLAY PROPERLY
February 2, 2018
Rajinder DeolHi Gajanand,
it this related to Aadhar card scanner
February 7, 2017
Sujeetthank you very much.
you just make my day.
February 8, 2017
Rajinder DeolGlad that I helped Sujeet, let me know if you need more help.
Also If you want to open the QR-Code scanner in Vertical Orientation then read my post : Android barcode Scanner Vertical Orientation.
February 21, 2017
ria gabiit helped me a lot.
for aadhar status registration and other procedure do visit my website dear rajinder deol.
https://indiaresultup.in/aadhaar-card-download-wwwuidaigovin/
aapki site best hai.!!
thumbs up!
February 27, 2017
Rajinder DeolHi Ria, I am glad that the post helped you, let me know if you need more help
February 27, 2017
ShrirajApp is working fine fantastic work deol ji
February 27, 2017
Rajinder Deolthanks for the kind words Shriraj
March 1, 2017
sneha girkarWe get the data from adhaar card in my app but we want to save the image of whole Adhaar Card also. please help me with this.
March 2, 2017
Rajinder DeolHi Sneha,
to save the image of aadhaar card you have to access the camera and prompt the user to click and save the image.
Later you have to show this image with the saved aadhaar card information and handle deleting this information when aadhar card data is deleted.
There is no one line answer to it but if you can wait, I will update the app code to include this feature over the weekend.
March 3, 2017
sneha girkarthank you for the prompt reply. It would be better if we get updated app code.
March 4, 2017
SangaviHi Rajinder Deol,
I had cloned your code from git hub but i cant able get details from QR code i can able to see yellow points while scanning but it takes to many time to scan and i cant get result can you plz help me to solve this problem. Thank you.
March 9, 2017
Rajinder DeolHi Sangavi,
This app works with images taken by your phone, so quality of the QR-code also matters.
Try to scan the QR-code of different aadhar cards. You can turn the camera flash on by using the volume-up button on your phone.
Try scanning few sample aadhar card found on google to test.
Let me know if you need more help.
March 17, 2017
SangaviHi,
Thanks for your response i had over come that issue by using some other quality qr image. now i had facing new problem if user come back without scanning qr code app tends force close
March 19, 2017
Rajinder DeolHi Sangavi,
I have fixed the issue, pull the latest code from my github repo. I have updated HomeActivity.java check https://github.com/rajdeol/android-aadhaar-card-scanner/blob/master/app/src/main/java/com/rajdeol/aadhaarreader/HomeActivity.java#L100
March 6, 2017
AMANDEEP SINGHHello Raj,
The post is useful. I have a question. Is it possible to connect the aadhaar card scanner to a database like sending a query to UIDAI database after the scanner scans the QR code and returns the information about the card holder in the format of a prefilled form.?
I am a novice in the field of IT and need help for my thesis. will be Thankful if you can help.
March 7, 2017
Rajinder DeolHi Aman,
UIDAI has an API end point which you can use to verify user information but there is no API to fetch user information. Due to the sensitivity of the user data you can only scan data from an Aadhaar card and send that data to verification API, the API will reply with just valid or not valid.
You can not get any information from UIDAI, it will only verify if the information matches to the information in their record, it will not disclose what mismatched just simple response as “invalid”.
Here is the PDF detailing the Authentication API https://uidai.gov.in/images/FrontPageUpdates/aadhaar_authentication_api_1_6.pdf
March 8, 2017
vinnyhi rajdeol
can you please explain working of zxing api and methodology used for this project?
March 9, 2017
Rajinder DeolHi Vinny,
zxing is an opensource image processing library written in Java and has its ports for other languages.
This library processes an image containing barcode or QR-code and returns the result.
This library has a default android implementation which uses camera with a framing rectangle to cut and extract image.
This extracted image which is a bitmap is processed by the library to guess the format and data in the barcode.
All this is available as “intent” so that you can directly use it in your Activity Class.
I hope this information is enough to get you started, if you would like to explore the source code it is available here : https://github.com/zxing/zxing
Feel free to ask if you need anything else.
March 8, 2017
ManmohanThank you so much.
Great Work!
March 9, 2017
Rajinder DeolHi Manmohan,
thanks for the kind words, do let me know if I can help you in anything.
March 16, 2017
PujanThank you very much…your work saves my final year project. Once again thanks
March 16, 2017
Rajinder Deolhi Pujan,
glad that my work helped you finishing your project, let me know if you need more help.
March 17, 2017
PujanHey brother, please help me to get image of Aadhar card user.
March 17, 2017
PujanOr Could i get registered mobile number??
March 16, 2017
PujanHey, i want also a photo of aadhar card.Is it possible?
March 16, 2017
PujanMeans user pic
March 17, 2017
PujanI want registered mobile number or user pic.Could you do this?
March 17, 2017
Rajinder DeolHi Pujan,
you can only read the information embedded into the QR-Code of Aadhaar card and QR-code only has Name, Address and Unique ID of user.
For User’s picture I am already working on updating the app to click picture of card and save along with the scanned data.
March 21, 2017
VasigaranYour code works perfectly. But I am in the work of expanding your codes and syncing it with the firebase database. I wish to store a particular amount to the aadhar id to scan and once i scan the card through the app, it should show my balance. How do I it?
March 27, 2017
Rajinder DeolHi Vasigaran,
you can do this pretty easily, add you code in the HomeActivity.java at this line https://github.com/rajdeol/android-aadhaar-card-scanner/blob/master/app/src/main/java/com/rajdeol/aadhaarreader/HomeActivity.java#L138
and send the UID back to firebase.
March 25, 2017
ruthrawhy format and content will be null while scanning aadhar card
March 27, 2017
Rajinder DeolHi Ruthra,
it will be null in two cases:
1. If you hit the back button from the scan screen
2. If the QR-Code you are scanning is not of good quality
let me know if you are facing any other scenario then the mentioned above.
April 29, 2017
mrmHi sir,
i am beginner to java…….can u help me for printing out a aadhaar text file containing details of aadhaar of a person…i want to just print to console the details in that text file in readable manner for eg: uid =: 123456789 name: xyz address:abcd and so on ……the file contains <PrintLetterBarcodeData uid = "123456789" name="xyz"
thanks a lot in advance
April 30, 2017
cristianHi, I don’t know why this app doesn’t work on both my devices.
When I scan a sample card, the app comes back to the home without saving any data.
What I can read on logcat is:
04-29 19:04:54.877 7900-7973/com.rajdeol.aadhaarreader E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f81ae4720
Any of the others your apps work good on both my devices…
May 1, 2017
Rajinder DeolHi Cristian,
there are two conditions in which the app will come back to home screen.
1. When scanned data is null at https://github.com/rajdeol/android-aadhaar-card-scanner/blob/master/app/src/main/java/com/rajdeol/aadhaarreader/HomeActivity.java#L94
2. When scanned data is empty, usually happen when user cancel the scan at https://github.com/rajdeol/android-aadhaar-card-scanner/blob/master/app/src/main/java/com/rajdeol/aadhaarreader/HomeActivity.java#L100
Try to debug these two cases in your app and see if these conditions are getting executed.
April 30, 2017
mrmHi sir,
i am beginner to java…….can u help me for printing out a aadhaar text file containing details of aadhaar of a person…i want to just print to console the details in that text file in readable manner for eg: uid =: 123456789 name: xyz address:abcd and so on ……the file contains <PrintLetterBarcodeData uid = "123456789" name="xyz"
thanks a lot in advance
May 1, 2017
Rajinder DeolHi,
the aadhar data file contains data in XML format. Learn about XML online and then read my post Android Aadhaar Card Scanner I have processed the XML and extracted the data. see processScannedData function at https://github.com/rajdeol/android-aadhaar-card-scanner/blob/master/app/src/main/java/com/rajdeol/aadhaarreader/HomeActivity.java#L117 I have used XmlPullParserFactory to process the XML string.
Try this and let me know if you need more help.
May 25, 2017
ajeetError:(17, 0) Could not find method compile() for arguments [directory ‘libs’] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File
Found this error on using code in build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url “http://dl.bintray.com/journeyapps/maven”
}
}
dependencies {
classpath ‘com.android.tools.build:gradle:2.3.1’
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
testCompile ‘junit:junit:4.12’
compile ‘com.android.support:appcompat-v7:23.4.0’
compile ‘com.journeyapps:zxing-android-embedded:2.0.1@aar’
compile ‘com.journeyapps:zxing-android-legacy:2.0.1@aar’
// Convenience library to launch the scanning and encoding Activities.
compile ‘com.journeyapps:zxing-android-integration:2.0.1@aar’
// for older Android versions.
compile ‘com.google.zxing:core:3.0.1’
// Added by raj ends
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
May 26, 2017
Rajinder DeolHi Ajeet,
You need to add the dependency in the build.gradle file in your app folder not the build.gradle at the root.
Can you please compare with the file at my github repo : https://github.com/rajdeol/android-aadhaar-card-scanner/blob/master/app/build.gradle
July 29, 2017
mujeebHii sir,
i want user info using aadhar number, eg:- i have aadhar card number while i search i need user info. Please help me for this.
July 29, 2017
Rajinder DeolHi Mujeeb,
user information is kept with government and you cannot get it by using Aadhar Card Number. There are APIs available to get that information and you need to register with UIDAI as a developer https://authportal.uidai.gov.in/developer
September 15, 2017
dharmendra794How can i get User profile picture on aadhar card in response, i am not getting profile picture url or anything else related to user profile picture. So can you please let me know that how can i get user profile url.
September 16, 2017
Rajinder DeolHi Dharmendra,
User profile pic is saved with government and it is not embeded in the QR-code. You cannot fetch a user’s image using the UUID.
Regards
Rajinder
October 13, 2017
kavyahi
I have used this code earlier only earlier it was working fine but now it’s not working crashing the application.
pleas help m
October 13, 2017
Rajinder DeolHi Kavya,
can you share the error your are getting, can you also share the logcat output.
November 2, 2017
AnuvidhyaHi this tutorial was simple and useful thank you so much. Can you please kindly do this with google vision api. I tried but scanner is not working for aadhar card.
November 2, 2017
Rajinder DeolThanks for the kind words Anu, I can give it a try to the google vision API and share the results in few weeks.
December 5, 2017
adminhi
i m matches two barcode and get json data in android dialogbox ,but barcode cannot matches , plzzz help me
December 9, 2017
Rajinder Deolhi dabhidhvani,
can you share more details, where are you getting your json from and are you comparing two strings ?
December 5, 2017
adminhi
i m matches two barcode and get json data in android dialogbox ,but barcode cannot matches , plzzz help me
February 19, 2018
Jagjeet SinghWhen scan qr code Error comes “Sorry, the android camera encountered a problem. You may need to restart the device”.
I try to restart a device but not working.
February 20, 2018
Rajinder DeolHi Jagjeet,
you have to test the app on a device, it will not work in the emulator. You also need to have camera permissions, so add camera permissions to your Androidmenifext.xml file. Refer to my post : https://rajislearning.com/android-barcode-scanner/
April 6, 2018
Raaju Yadavtest the app on a device, not working
April 11, 2018
Rajinder DeolHi Raju,
thanks for reporting it, I tested and although we specify the camera permissions in the menifest file, the permissions were not grated to app. I have updated the code and added check for camera permissions in the ScanNow() function. Please get the latest code from my github repositoy : https://github.com/rajdeol/android-aadhaar-card-scanner
April 24, 2018
Ganga ArpithaHello Sir,
Your Code is perfectly working and it is same as what i need with slight difference. Your code is scanning the adhar card and i need to scan qr code of a goods permit. In my requirement i need Permit Number,Permit Code,Commodity Name etc I have done the modification to my code but its not scanning.
Please suggest me how can i modify??
July 24, 2018
Rajinder DeolHi Ganga,
apologies for the late reply, I was travelling. Can you share a link to your code so that I can check what all modification you have done.
January 23, 2019
harpreethello sir,
I am not able to resolve DataAttributes package error.
its showing cannot resolve DataAttributes.
please help me..
January 23, 2019
Rajinder DeolHi Harpreet,
can you share some more details, like the error message and file/line of code where you are getting this error.
March 29, 2019
Ruban JHai Rajinder
Your repo code works fine, but I have implement into my app it not works.
March 29, 2019
Rajinder DeolHi Ruban,
are you getting any error? Can you share more details.
April 2, 2019
Ruban JActually I have using two Camera icon in same fragment, also scanner feature via button click, now my problem
so request code for scanner not works.
( OCR_REQUEST = 49374 ) if pressed the button Scanner opens but data not get from Aadhar. Can you help me?
Thanks in advance.
April 2, 2019
Ruban JHere I explains as below
Camera Icon Click Events:
—————————
case R.id.reg_2_profile_camera:
if (ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
{
requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_CAMERA_PERMISSION_CODE);
}
else
{
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
break;
————————————————-
REQUEST PERMISSION
————————————————-
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == MY_CAMERA_PERMISSION_CODE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//Toast.makeText(getActivity(), “camera permission granted”, Toast.LENGTH_LONG).show();
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
} else {
Toast.makeText(getActivity(), “camera permission denied”, Toast.LENGTH_LONG).show();
}
}
}
——————————————————
ACTIVITY RESULT
—————————————————-
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK)
{
Bitmap photo = (Bitmap) data.getExtras().get(“data”);
profileImg.setImageBitmap(photo);
}
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (scanningResult != null) {
String scanContent = scanningResult.getContents();
String scanFormat = scanningResult.getFormatName();
// process received data
if (scanContent != null && !scanContent.isEmpty()) {
processScannedData(scanContent);
} else {
Toast.makeText(getActivity(), “Scan Cancelled”, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getActivity(), “No scan data received!”, Toast.LENGTH_SHORT).show();
}
}
April 3, 2019
Ruban JAre you review my code?
April 3, 2019
Ruban JThanks for your coding , my problem is in Fragment.So as below line solved the issue.
IntentIntegrator integrator = new IntentIntegrator(this.getActivity()).forSupportFragment(this);
April 4, 2019
Rajinder DeolHi Ruban,
apologies for the late reply, I was caught up at work. Glad to know that you have solved the issue. All the best for your project and let me know if you need any help.
April 5, 2019
Ruban JHow to set Camera focus on QR Code?
Also If possible, capture image from Aadhar card?
Kindly let me know.
April 5, 2019
Ruban JHi Rajinder Deol,
Actually we coded for as below type format
<PrintLetterBarcodeData
uid="XXXXXXXXXX"
name="XXXXXXXX"
gender="XX"
yob="XXXX"
in case aadhaar as blow format? what we have you have any idea or suggestions ?
<QPDB
n="XXXXXXX"
u="xxxxxxxxxxx"
g="x"
m="xxxxxxxxxx"
d="xxxxxxxxxx"
April 6, 2019
Rajinder DeolHi Ruban,
when we are reading data created by third party(in our case UIDAI which decides aadhar card data) there will always be situations where they will change the format as per their needs. To handle cases like these, we always abstract these data identifiers into separate files so that we have to do minimal changes.
In our application we have done the same and created DataAttributes.java file which is located in utils folder (github). You can simply change the values in this file and the code will work.
April 11, 2019
Ruban JHai Rajinder
you have any idea about in Recyclerview content convert to PDF format?
May 3, 2019
Ruban JI have found the Solution
https://stackoverflow.com/questions/45545782/creating-pdf-file-using-itext-from-a-recyclerview-entire-items-inside-in-andro
June 18, 2019
VenuHi,
Can You explain me how can i get image view while aadhar card scan in this code because I need to display image in my code. can you please tell me
June 23, 2019
Rajinder DeolHi Venu,
The image view is used in the scan to capture the QR-code, Once the scan is successful you need to add another action to capture the image on the Aadhar Card. This will be a separate function than the QR-code scan which should be called in the code after processing and displaying the scanned data.
After Code Line at – Github repository at
June 26, 2019
VenuHow to convert byte array to bitmap, beacause i am getting null value in bitmap from byte see the my code below.
String scanContent = result.getContents();
String scanFormat = result.getFormatName();
byte[] rawBytes = result.getRawBytes();
BigInteger bigInteger= new BigInteger(rawBytes);
// BigInteger bigInteger= new BigInteger(“6979414848205548481619299442879901900893978332594614407044767717485407280104077714658698163325401659212830920734233047578454701810567032015270223682917915825234703754712504887921309181789607809168884583848396456653007022479356336240198130363930881632367124738541517499494458139647378808680614169273221404741476596583953169248831376224396335169577064812987140578144885819479190173537644970232125142253963784979138011318798385442436099901621998283624816070080504830712594525760596934341576755626791590403636878139861665599383319429228364434183913197958738697001410493839281298692342829951566712530309758759364649701153639921979798429707566199261950037418171329283207372048014948669160666776198414040633384677104717697507521717586776709084200364956178863636105988867260929887577092955570407803783021397897341999914616790441029837229129746669225095633201097644321593502503404440714110515167034889128258965583435965030225845348564582051521348800742574442877087774194668983516629631073341202705453382780613775427336949283388084891654484225446940941660942440637784744293259916479841407088189462964489670231866481904237338494872813098890875845640034370370387108798950180220865436012752487216677041817312930119747601017807577565413977545693375480131324240696099879479436722576566447939593195590684591261809038023122178172006150499569185218838749337238281597037288924464009997530938336798176023597292328320965086990184531426188862965408313308973495924965144113396593829090645266653313774582036138982013368561474719154447134894466611560589758251829063226370300282175823479569847261439348404558251402273730865053482214589180028302043821438357583302818374143973997002745047526405755760407045006694423501337081780299815080324840337828812644300041900356816429114261098230198976752026002079876882796597235615015594486182057781476152918170746403157005216896239428521706033466061587608065036133153074432195952131368564234168005447770190345777024917629879639171161719929852078265309160759260989590618158889891835294735614366674503961584445497685736312628248483551986529867423016255476553691922054241686230968975229511700928171281549902682365302333677412951788839806869796040512235899311734337858684531156721416280114473368826463098485252394260075790386415875290922570568686439586036262465414002334117870088922801660529414759784318799843806130096998190881240404138869293309782335305296720666220243304175086358278211355789957998014801209332293458940463859106591986434520433810583569309224929264228263841477378949329312443958215939294432669464260216534074560882723006838459792812340253078330291135526952675203790833430237852831740601433198364243363569730205351077393441691141240055900819091229931605146865520183001810239708464322588389956036291760175558843819105418234580239610174323636606095262722940143706063698846499673285377621180570537788160304936809915237889489342387891057012783726694920184573202789672963922380028271124448024265644396686341508447830351380242127542393849410283830409594988503246799544444687606954881510597515686410993828907588979699141180160893062603338104857903239845856783130275935413569275439908789983311663211937449259444259898972766208”);
byte[] bigBytes=bigInteger.toByteArray();
byte[] decompressed = decompressByteArray(bigBytes);
byte[] firstBytes = Arrays.copyOfRange(decompressed,0,256);
String str = new String(firstBytes, StandardCharsets.ISO_8859_1);
System.out.println(str);
byte[] photoBytes = Arrays.copyOfRange(rawBytes,0,rawBytes.length-321);
Bitmap bitmap = BitmapFactory.decodeByteArray(photoBytes,0,photoBytes.length);
byteimage.setImageBitmap(bitmap);
August 24, 2019
Arnab BanerjeeThanks for this tutorial. I am doing my final year project and need to send an OTP to the registered mobile number of the Aadhaar card which the user will scan. How can this be done? Is there any way of getting the registered mobile number?
March 17, 2020
Rajinder DeolHi Arnab,
mobile number is not displayed on the Aadhar Card and it is not available via scanning QR code on Aadhar Card. This information is with government and you need to register your application with government to access this information. For more details please read developer section on Aadhar. website at https://www.uidai.gov.in/914-developer-section.html
August 24, 2019
Arnab BanerjeeHow can I print the entire set of information that we get after scanning the Aadhaar QR code?
March 17, 2020
Rajinder DeolHi Arnab,
you can create a PDF from the information that you receive from the QR code and then that can be printed. You can use android.graphics.pdf api for creating PDF, for more information read https://developer.android.com/reference/android/graphics/pdf/PdfDocument
March 17, 2020
sanjoo thomasHi sir,
it is very good app.I am android developer i like to add this feature to my app.So i tried this in different cards but not getting result from most of the cards only getting result from old card.
I am expecting a reply from your side.
Thank you
March 17, 2020
Rajinder DeolHi Sanjoo,
I have implemented this on scanning QR code on Aadhar cards back in 2015, they might have changed the data in the new Aadhar cards. I don’t have any new Aadhar card, if you can share few images of QR code of new Aadhar cards then I will update the code accordingly
March 17, 2020
sanjoo thomashi brother while reading some of the cards getting some errors and get back to the home page
This is the error i am getting
org.xmlpull.v1.XmlPullParserException: name expected (position:END_TAG @1:3 in java.io.StringReader@63651fc)
March 17, 2020
Rajinder DeolI think the xml string in the QR code is changed, can you share the scanned xml string, I am logging the scanned string in the logs, check this line https://github.com/rajdeol/android-aadhaar-card-scanner/blob/master/app/src/main/java/com/rajdeol/aadhaarreader/HomeActivity.java#L136
March 17, 2020
sanjoo thomas2020-03-17 15:47:10.284 6050-6050/com.rajdeol.aadhaarreader D/Rajdeol:
2020-03-17 15:47:10.285 6050-6050/com.rajdeol.aadhaarreader D/Rajdeol: Start document
April 3, 2020
Ankur Kumarhi Bro this is scan data
7673947780674466563660121149922162062069931582809490058001533780273293649777869827945716061736730831527794179517234643007910463488058377140245192562814037333410222796696765216965998908087047784846452581667157626611634247752201353110539154993358191697991862197454937979243211180034179499033625116912906827865467575650135521672218994195679928987072869507341454395872395695921666163042249030334084872869953154015667215600067147517572348698216816196598470043018141197637206799817086778691160830481165792862281797666284410942127043691272905050238797860183169715720313945079873639170879167012108277797195451556719353339646479953710680527179284187462822606408144407015057441712506585042399748970970052035835832276019608449579071731435245207025161162400210163807146633501027341690355055516312437516024394863419587161837261981718004046475287726394970303271686761157537440383954487562312239264502603740402251280707726386325581371075043384232105951215625293892951977316591110989859398644911405790177079271748326905923289576617173523560095752457612352222219314723015876354012433251073544936570007185576104076488653117506252497888984823355109708258897984344638023796004507953900297218120447762648776832478925018024890279682769714890380130153529549509400040978083836106344326083948468416985945611840692658419161797275744331476785068804010113369322965987741328504030660147028579055382861419561147056489285069543520329085143078689487088497974138333016670787228973578706893926161220339012417102846102703848714573554408194643785185013651732060788653715222366128932319726682357059559200697450186427862948608036695982744674091476877256136833637012439924715612140282030521666464217948732353032624614927123086334953367988413857392324167929820547601015414271605818874685846902811836896328745061166867626188304613404578683787654085968998137871251238436864133246678660455984626901977196598693862330811935305419088941700740181071619847749111384038804414775073698983189286781303373955051795577245974383983314958412008579195410851125971614110096262407090254271122386840769163153393761540907539782799732094952271266622616634943054694668772900905597574159255292156581130988830853997095460385011099885368655023217340547153661308974502603671734455331712839977650224421729929368509227283863515022020106217396381926611511111213969736671301618602349428433361503079982408074346383379943773025211160016616672398346614618047249509961867219115743665137195419142589768660736583544379515703170761697509484322233110786206524971733005209231088951252689128495738616223495871967626339438442034947201467067225978776712777995600102556622146544057467458286469701078272669452704950611449879976431797814323409466538316137853896400390103602522416650453216280684711603730657657351933204647161222910928190719495775091885183245719733352475697615179889678406408706908193412741225544757334601124219018313298134643561705738700650647633930864242101510215895662750192382668316209587424256765441766302067171960734040255490613536405300277832609914134916326402777017712408531997501554623090061535018701252205683510185749858373618760903576621412253062169532801561314251652467501989336523281338613615052532540483371008
this is error
org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT 7673947780674466…@1:3155 in java.io.StringReader@bb25ceb)
How to solve this
April 7, 2020
Rajinder DeolHi Ankur,
Aadhar has changed the data recently, I am reading the docs and will write another post, just gimme few days and I will share an update.
February 24, 2021
Deepakhello sir
any update for this type errors
February 24, 2021
Deepakhello ankur kumar
you have any solution for this
March 30, 2020
Rishav Mishrahi brother can we read only required data and as you said format of data is changed for new qr code
what i found is
https://uidai.gov.in/ecosystem/authentication-devices-documents/qr-code-reader.html
data format of stored in qr code
March 30, 2020
Rajinder DeolHi Rishav,
thanks for sharing the reference, I will update the post as per the new secured QR-code guidelines or might write a new post
April 1, 2020
Rishav Mishrahttps://uidai.gov.in/images/resource/User_manulal_QR_Code_15032019.pdf
March 31, 2020
nagarjunaHi raj,
I could not able to read data from mAadhaar image,getting BigInteger(direct downloaded from mAadhaar site).But while taking image of Aadhaar card QR code(using snipping tool i created new image), I can able to read data.Could you please help.
BigInteger bigIntegerStr=new BigInteger(xmlString);
//System.out.println(“bigIntegerStr–>”+bigIntegerStr);
byte b1[] = bigIntegerStr.toByteArray();
byte[] content = deCompressByteArray(b1);
System.out.println(“content length–>”+content.length);
String mAadhaar = new String(content, 0, 255, “ISO-8859-1”);
System.out.println(“mAadhaar–>”+mAadhaar);
/*String photo = new String(content, 256, 255, “ISO-8859-1”);
System.out.println(“photo–>”+photo);
String email = new String(content, 512, 255, “ISO-8859-1”);
System.out.println(“email–>”+email);
String mobile = new String(content, 768, 255, “ISO-8859-1”);
System.out.println(“mobile–>”+mobile);*/
byte[] sliceMobile = Arrays.copyOfRange(content, content.length-1-256-32, content.length);
String resultMobile = toHexString(sliceMobile);
System.out.println(“resultMobile : ” + resultMobile);
byte[] sliceEmail = Arrays.copyOfRange(content, content.length-1-256-32-32, content.length);
String resultEmail = toHexString(sliceEmail);
System.out.println(“resultEmail : ” + resultEmail);
April 7, 2020
Rajinder DeolHi Nagarjuna,
can you share your code via github or bitbucket ? it will be a lot easier for me to get a sense of the issue if the see some more code.
April 13, 2020
ManishaHi Rajinder,
I want to save the adhaar card details in database and fetch details from database.Can you please tell me what changes I need to do in your code?
April 13, 2020
Rajinder DeolHi Manish,
where is your database ? Do you want to use the space on the mobile phone of the user or do you have your database setup on a remote server ?
July 13, 2020
sagarHI Rajinder,
Thanks for the solution. but this solution will not work now as all new QR codes of aadhar are secured. it need government client only to read the Qr data. i belive its now impossible to read qr data of new aadhars.
Regards,
Sagar
July 13, 2020
Rajinder DeolHi Sagar,
I have built the solution to scan the secured Aadhar card and I have tested it with sample QR codes, but I need a real secure Aadhar card and their security code to test and finish the solution. If you have the new secure Aadhar Card image and the security code then please mail me, do not share it here in comments as you are not suppose to share your security code.
September 8, 2020
KaboHello Rajinder,
Thanks for your amazing post and love it. In short, I love to integrate in our app.
Is your latest GitHub code can handle/scan the secure Aadhar card..?
Another requirement is I would like to push/fetch the Aadhar card details from our remote MySQL database. For this either your code can manage it or do I need to add extra work on your code.
Your urgent response is highly appreciated.
Regards,
Kabo Technologies
September 9, 2020
Rajinder DeolHi Kabo,
I have the updated code to scan secure aadhar card QR-Code, just need to clean up and then I will push it to my github. Just very busy with my day job right now. I will finish it over the weekend.
For saving and fetching the data from your database you need to write more code. You need to build REST APIs for the backend and then use those APIs in the android app.
September 9, 2020
KaboHi Rajinder,
Thank you for your quick turnaround.
And waiting for your latest github push.
Best Regards,
Kabo
January 28, 2021
Sonali MajalekarHi sir,Myself Sonali working as a android developer I chech all code it is very nice but when run in my android studio i get this error: [java.lang.IllegalArgumentException: 187 > 186
at android.app.ActivityThread.deliverResults(ActivityThread.java:4761)
What I do for this..
February 25, 2021
Rajinder DeolCan you please share the full error string, just want to narrow down the file you are getting the error in
January 28, 2021
Sonali MajalekarHi sir,
I get all scaned data but cant get UID.What I do for getting UID of scanned adhar card…
February 25, 2021
Rajinder DeolHi Sonali,
are you scanning the new secure QR code or the old code
February 25, 2021
DeepakHello Sir
how to get uid because i am getting uid null
February 25, 2021
Rajinder DeolHi Deepak,
what is the output of your scanned QR code, can you share the string which is scanned
March 1, 2021
Deepakhello sir
thanks for reply my scanned output is 7673947780674466563660121149922162062069931582809490058001533780273293649777869827945716061736730831527794179517234643007910463488058377140245192562814037333410222796696765216965998908087047784846452581667157626611634247752201353110539154993358191697991862197454937979243211180034179499033625116912906827865467575650135521672218994195679928987072869507341454395872395695921666163042249030334084872869953154015667215600067147517572348698216816196598470043018141197637206799817086778691160830481165792862281797666284410942127043691272905050238797860183169715720313945079873639170879167012108277797195451556719353339646479953710680527179284187462822606408144407015057441712506585042399748970970052035835832276019608449579071731435245207025161162400210163807146633501027341690355055516312437516024394863419587161837261981718004046475287726394970303271686761157537440383954487562312239264502603740402251280707726386325581371075043384232105951215625293892951977316591110989859398644911405790177079271748326905923289576617173523560095752457612352222219314723015876354012433251073544936570007185576104076488653117506252497888984823355109708258897984344638023796004507953900297218120447762648776832478925018024890279682769714890380130153529549509400040978083836106344326083948468416985945611840692658419161797275744331476785068804010113369322965987741328504030660147028579055382861419561147056489285069543520329085143078689487088497974138333016670787228973578706893926161220339012417102846102703848714573554408194643785185013651732060788653715222366128932319726682357059559200697450186427862948608036695982744674091476877256136833637012439924715612140282030521666464217948732353032624614927123086334953367988413857392324167929820547601015414271605818874685846902811836896328745061166867626188304613404578683787654085968998137871251238436864133246678660455984626901977196598693862330811935305419088941700740181071619847749111384038804414775073698983189286781303373955051795577245974383983314958412008579195410851125971614110096262407090254271122386840769163153393761540907539782799732094952271266622616634943054694668772900905597574159255292156581130988830853997095460385011099885368655023217340547153661308974502603671734455331712839977650224421729929368509227283863515022020106217396381926611511111213969736671301618602349428433361503079982408074346383379943773025211160016616672398346614618047249509961867219115743665137195419142589768660736583544379515703170761697509484322233110786206524971733005209231088951252689128495738616223495871967626339438442034947201467067225978776712777995600102556622146544057467458286469701078272669452704950611449879976431797814323409466538316137853896400390103602522416650453216280684711603730657657351933204647161222910928190719495775091885183245719733352475697615179889678406408706908193412741225544757334601124219018313298134643561705738700650647633930864242101510215895662750192382668316209587424256765441766302067171960734040255490613536405300277832609914134916326402777017712408531997501554623090061535018701252205683510185749858373618760903576621412253062169532801561314251652467501989336523281338613615052532540483371008
this scanned string is new secaure type.i am getting refrence id but refrence id have only last four dizits of uid how to get full uid.
March 1, 2021
DeveshHello sir
Please suggest how to parse pan card scanned qr string with this code.
thanks in advance.
March 10, 2021
DeepakHello sir
Please give me reply how to get full uid after scanned new secure type string.
Thanks Again.
April 2, 2021
Kabilanjava.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=49374, result=-1, data=Intent { act=com.google.zxing.client.android.SCAN flg=0x80000 (has extras) }} to activity {com.rajdeol.aadhaarreader/com.rajdeol.aadhaarreader.HomeActivity}: java.lang.NumberFormatException: Invalid BigInteger:
April 10, 2021
swapnil malihello rajindar deol sir,
I’m getting NumberPointerException in HomeActivity=>processEncodedScanData=>SecureQRCode()=> final BigInteger bigIntScanData = new BigInteger(scanData,10);
and also can this library is usable in kotlin?
October 12, 2021
Mukesh Yadavhello sir ,in your Source Code,in qrScanner and Home Activty ,lots of error Are showing in ProcessEncodedScannedData method,then what can i do ??
December 30, 2022
Bhagwan SahaneHi,
We have came across this reference to decode secure QR code from Aadhaar card and able to decode everything except photo.
We are facing some issues while converting photo from JP2000 byte array format to jpeg image in Java to display on webpage.
Can anyone quickly help with this?
Thanks in advance,
Bhagwan Sahane
December 7, 2023
CJHi Rajinder,
good to see this code in your portal. Nice application. But I am getting an error at below snippet at final BigInteger bigIntScanData = new BigInteger(scanData,10);
public SecureQrCode(Context activity,String scanData) throws QrCodeException{
mContext = activity;
scannedAadharCard = new AadharCard();
// 1. Convert Base10 to BigInt
final BigInteger bigIntScanData = new BigInteger(scanData,10);
Error message:
ResultInfo{who=null, request=49374, result=-1, data=Intent { act=com.google.zxing.client.android.SCAN flg=0x80000 (has extras) }}
is it resolved in the latest source code? If so, please share the link here to verify…
Thanks