Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
In response to the comment Android QR-Code Scanner After scanning a QR-Code check and verify if it is a HTTP URL and open it in a webview
package in.whomeninja.android_barcode_scanner;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class HomeActivity extends ActionBarActivity {
private String codeFormat,codeContent;
private TextView formatTxt, contentTxt;
private WebView main_web_view;
protected void onCreate(Bundle savedInstanceState) {
formatTxt = (TextView)findViewById(;
contentTxt = (TextView)findViewById(;
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == {
return true;
return super.onOptionsItemSelected(item);
* event handler for scan button
* @param view view of the activity
public void scanNow(View view){
IntentIntegrator integrator = new IntentIntegrator(this);
// set to scan QR-Code
integrator.setWide(); // Wide scanning rectangle, may work better for 1D barcodes
integrator.setCameraId(0); // Use a specific camera of the device
* function handle scan result
* @param requestCode scanned code
* @param resultCode result of scanned code
* @param intent intent
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
if(scanContent != null && !scanContent.isEmpty()){
Toast toast = Toast.makeText(getApplicationContext(),"Scan Cancelled", Toast.LENGTH_SHORT);;
Toast toast = Toast.makeText(getApplicationContext(),"No scan data received!", Toast.LENGTH_SHORT);;
* process xml string received from aadhaar card QR code
* @param scanData
protected void processScannedData(String scanData){
// test if string is a valid URL
// open in a webview, this webview should be added in your layout
main_web_view = (WebView) findViewById(;
//enable javascript
// load URL
// error
Toast toast = Toast.makeText(getApplicationContext(),"Scanned String is not valid URL", Toast.LENGTH_SHORT);;
}// EO function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.