Saturday , October 23 2021

Android QR Code Scanner Tutorial using Zxing Library – Android Coding by DMTechnolab

The package The trap.Simplified coding.androidqrcodescanner;

Import Android.Content.Intent;

Import Android.Support.v7.App.AppCompatActivity;

Import Android.The.Bundle;

Import Android.Opinion.Opinion;

Import Android.Widget.switch;

Import Android.Widget.text view;

Import Android.Widget.Toast;

Import With.Google.Chimes.Integration.Android.Intent;

Import With.Google.Chimes.Integration.Android.the intention;

Import org.Jasan.JSONException;

Import org.Jasan.JSONObject;

// implement onclicklistener

public class Main activity Is spread AppCompatActivity come into force Opinion.OnClickListener {{

// view items

Private switch switch;

Private text view textViewName, textViewAddress;

// qr code scanner object

Private Intent qrScan;

@Override

Protected Zero Go ahead()Bundle saveInstanceState) {{

Super.Go ahead()saveInstanceState);

setContentView()R.Layout.activity_main);

// view items

switch = ()switch) findViewById()R.Id.switch);

textViewName = ()text view) findViewById()R.Id.textViewName);

textViewAddress = ()text view) findViewById()R.Id.textViewAddress);

// intializing scan object

qrScan = New Intent()this);

// attachment listener

switch.setOnClickListener()this);

}

// get scan results

@Override

Protected Zero onActivityResult()int request code, int results, Intent The data) {{

the intention results = Intent.parseActivityResult()request code, results, The data);

If ()results ! = Invalid) {{

// if there is nothing in qrcode

If ()results.getContents()) == Invalid) {{

Toast.Makeup()this, “Results not found”, Toast.LENGTH_LONG).Display());

} other {{

// if qr contains data

try {{

// convert data to json

JSONObject obj = New JSONObject()results.getContents()));

// Setting the value for textbooks

textViewName.Settext()obj.Get up()“Name”));

textViewAddress.Settext()obj.Get up()“Address”));

} Hold ()JSONException I) {{

I.Printstacktress());

// if control comes here

// means that the encoded format does not match

// In this case you can display whatever data is available on qrcode

// for a toast

Toast.Makeup()this, results.getContents()), Toast.LENGTH_LONG).Display());

}

}

} other {{

Super.onActivityResult()request code, results, The data);

}

}

@Override

public Zero on click()Opinion Opinion) {{

// start qr code scan

qrScan.To start());

}

}


Source link

About dmtechnolab

Check Also

Simplified Coding

Android Espresso Tutorial – Testing Fragment in Isolation – Android Coding by DMTechnolab

Welcome to another tutorial in the Android test series. And this post is called Android …

Leave a Reply

Your email address will not be published. Required fields are marked *