How scan the data through Aadhar Card in Android.
First we need to add Library to our project.
compile 'com.journeyapps:zxing-android-embedded:2.0.1@aar'
compile 'com.journeyapps:zxing-android-legacy:2.0.1@aar'
compile 'com.journeyapps:zxing-android-integration:2.0.1@aar'
compile 'com.google.zxing:core:3.0.1'
Creating New Project.
Open android studio and create a new project.
File => New => New Project => Configure your new project => Select the form factor yours app will run on => Add an Activity to Mobile => Customize the Activity => Finish.
Create the Java file in project.
Open app => main => src = MainActivity.java
Create Xml file in project.
Open => app => res => layout - activity_main.xml.
<LinearLayout
android:id="@+id/ll_scan_qr_wrapper"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#fff"
android:padding="8dp"
android:orientation="horizontal"
android:onClick="scanNow">
<!-- scanner -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.50">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@mipmap/qr_scanner"/>
</LinearLayout>
Create the Java file in project.
Open app => main => src = MainActivity.java
String uid,user_name,gender,yearOfBirth,careOf,villageTehsil,postOffice,district,state,postCode;
LinearLayout ll_scanned_data_wrapper = (LinearLayout)findViewById(R.id.ll_scan_qr_wrapper);
/**
* onclick handler for scan new card
* @param view
*/
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();
}
/**
* function handle scan result
* @param requestCode
* @param resultCode
* @param intent
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
super.onActivityResult(requestCode, resultCode, intent);
callbackManager.onActivityResult(requestCode, resultCode, 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
if(scanContent != null && !scanContent.isEmpty()){
processScannedData(scanContent);
}else{
}
}else{
}
}
/**
* process xml string received from aadhaar card QR code
* @param scanData
*/
protected void processScannedData(String 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) {
} 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
user_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) {
} else if(eventType == XmlPullParser.TEXT) {
}
// update eventType
eventType = parser.next();
}
// display the data on screen
displayScannedData();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}// EO function
/**
* show scanned information
*/
public void displayScannedData(){
String mName=user_name;
String mUid=uid;
String name=gender;
}
Add Internet permission in your manifest.
<uses-permission android:name="android.permission.INTERNET" />
First we need to add Library to our project.
compile 'com.journeyapps:zxing-android-embedded:2.0.1@aar'
compile 'com.journeyapps:zxing-android-legacy:2.0.1@aar'
compile 'com.journeyapps:zxing-android-integration:2.0.1@aar'
compile 'com.google.zxing:core:3.0.1'
Creating New Project.
Open android studio and create a new project.
File => New => New Project => Configure your new project => Select the form factor yours app will run on => Add an Activity to Mobile => Customize the Activity => Finish.
Create the Java file in project.
Open app => main => src = MainActivity.java
Create Xml file in project.
Open => app => res => layout - activity_main.xml.
<LinearLayout
android:id="@+id/ll_scan_qr_wrapper"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#fff"
android:padding="8dp"
android:orientation="horizontal"
android:onClick="scanNow">
<!-- scanner -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.50">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@mipmap/qr_scanner"/>
</LinearLayout>
Create the Java file in project.
Open app => main => src = MainActivity.java
String uid,user_name,gender,yearOfBirth,careOf,villageTehsil,postOffice,district,state,postCode;
LinearLayout ll_scanned_data_wrapper = (LinearLayout)findViewById(R.id.ll_scan_qr_wrapper);
/**
* onclick handler for scan new card
* @param view
*/
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();
}
/**
* function handle scan result
* @param requestCode
* @param resultCode
* @param intent
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
super.onActivityResult(requestCode, resultCode, intent);
callbackManager.onActivityResult(requestCode, resultCode, 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
if(scanContent != null && !scanContent.isEmpty()){
processScannedData(scanContent);
}else{
}
}else{
}
}
/**
* process xml string received from aadhaar card QR code
* @param scanData
*/
protected void processScannedData(String 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) {
} 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
user_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) {
} else if(eventType == XmlPullParser.TEXT) {
}
// update eventType
eventType = parser.next();
}
// display the data on screen
displayScannedData();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}// EO function
/**
* show scanned information
*/
public void displayScannedData(){
String mName=user_name;
String mUid=uid;
String name=gender;
}
Add Internet permission in your manifest.
<uses-permission android:name="android.permission.INTERNET" />
hello sir,
ReplyDeleteI am unable to resolve the data attribute package..
please help me with that
where is Data attribute??
ReplyDelete