Android QR reader using zxing display white empty activity

zxing qr code scanner android example github
zxing scanner view in android
zxing qr code scanner android studio example
android barcode scanner library
zxing barcode scanner

I am using the below activity code to scan QR code:

import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.google.zxing.Result;

import me.dm7.barcodescanner.zxing.ZXingScannerView;

import static android.Manifest.permission_group.CAMERA;

public class QRScannerActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {

private static final int REQUEST_CAMERA = 1;
private ZXingScannerView scannerView;
private static int camId = Camera.CameraInfo.CAMERA_FACING_BACK;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    scannerView = new ZXingScannerView(this);
    setContentView(scannerView);
    int currentApiVersion = Build.VERSION.SDK_INT;

    if(currentApiVersion >=  Build.VERSION_CODES.M)
    {
        if(checkPermission())
        {
            Toast.makeText(getApplicationContext(), "Permission already granted!", Toast.LENGTH_LONG).show();
        }
        else
        {
            requestPermission();
        }
    }
}

private boolean checkPermission()
{
    return (ContextCompat.checkSelfPermission(getApplicationContext(), CAMERA) == PackageManager.PERMISSION_GRANTED);
}

private void requestPermission()
{
    ActivityCompat.requestPermissions(this, new String[]{CAMERA}, REQUEST_CAMERA);
}

@Override
public void onResume() {
    super.onResume();

    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= android.os.Build.VERSION_CODES.M) {
        if (checkPermission()) {
            if(scannerView == null) {
                scannerView = new ZXingScannerView(this);
                setContentView(scannerView);
            }
            scannerView.setResultHandler(this);
            scannerView.startCamera();
        } else {
            requestPermission();
        }
    }
}

@Override
public void onDestroy() {
    super.onDestroy();
    scannerView.stopCamera();
}

public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case REQUEST_CAMERA:
            if (grantResults.length > 0) {

                boolean cameraAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
                if (cameraAccepted){
                    Toast.makeText(getApplicationContext(), "Permission Granted, Now you can access camera", Toast.LENGTH_LONG).show();
                }else {
                    Toast.makeText(getApplicationContext(), "Permission Denied, You cannot access and camera", Toast.LENGTH_LONG).show();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        if (shouldShowRequestPermissionRationale(CAMERA)) {
                            showMessageOKCancel("You need to allow access to both the permissions",
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                                requestPermissions(new String[]{CAMERA},
                                                        REQUEST_CAMERA);
                                            }
                                        }
                                    });
                            return;
                        }
                    }
                }
            }
            break;
    }
}

private void showMessageOKCancel(String message, DialogInterface.OnClickListener okListener) {
    new android.support.v7.app.AlertDialog.Builder(QRScannerActivity.this)
            .setMessage(message)
            .setPositiveButton("OK", okListener)
            .setNegativeButton("Cancel", null)
            .create()
            .show();
}

@Override
public void handleResult(Result result) {
    final String myResult = result.getText();
    Log.d("QRCodeScanner", result.getText());
    Log.d("QRCodeScanner", result.getBarcodeFormat().toString());

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Scan Result");
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            scannerView.resumeCameraPreview(QRScannerActivity.this);
        }
    });
    builder.setNeutralButton("Visit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myResult));
            startActivity(browserIntent);
        }
    });
    builder.setMessage(result.getText());
    AlertDialog alert1 = builder.create();
    alert1.show();
    /*MessageSender messageSender = new MessageSender();
    messageSender.execute(result.getText().toString());*/

}
}

Manifest file permissions:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.hardware.camera" />
<uses-permission android:name="android.hardware.camera.autofocus" />

build.gradle added compile line in dependencies:

compile 'me.dm7.barcodescanner:zxing:1.9'

All i get is a white blank activity when i run on my samsung phone Android: 4.4.4

and the following errors:

05-28 08:56:59.751 1381-1381/? E/SamsungIME: AbstractCandidateLayout-setCandidates suggestions count : 9
05-28 08:56:59.761 1381-1381/? E/SamsungIME: SwiftkeyWrapper-inputKey
05-28 08:56:59.941 1381-1381/? E/SamsungIME: AbstractCandidateLayout-setCandidates suggestions count : 9
05-28 08:57:00.831 235-235/? E/SMD: DCD ON
05-28 08:57:03.591 750-1132/? E/Watchdog: !@Sync 199
05-28 08:57:03.841 235-235/? E/SMD: DCD ON
05-28 08:57:06.841 235-235/? E/SMD: DCD ON
05-28 08:57:09.841 235-235/? E/SMD: DCD ON
05-28 08:57:12.841 235-235/? E/SMD: DCD ON
05-28 08:57:15.841 235-235/? E/SMD: DCD ON
05-28 08:57:18.851 235-235/? E/SMD: DCD ON
05-28 08:57:21.851 235-235/? E/SMD: DCD ON
05-28 08:57:24.852 235-235/? E/SMD: DCD ON
05-28 08:57:27.851 235-235/? E/SMD: DCD ON
05-28 08:57:30.851 235-235/? E/SMD: DCD ON
05-28 08:57:33.601 750-1132/? E/Watchdog: !@Sync 200
05-28 08:57:33.861 235-235/? E/SMD: DCD ON
05-28 08:57:36.861 235-235/? E/SMD: DCD ON
05-28 08:57:39.861 235-235/? E/SMD: DCD ON
05-28 08:57:42.861 235-235/? E/SMD: DCD ON
05-28 08:57:45.861 235-235/? E/SMD: DCD ON
05-28 08:57:48.871 235-235/? E/SMD: DCD ON
05-28 08:57:51.871 235-235/? E/SMD: DCD ON
05-28 08:57:54.871 235-235/? E/SMD: DCD ON
05-28 08:57:57.871 235-235/? E/SMD: DCD ON
05-28 08:58:00.881 235-235/? E/SMD: DCD ON
05-28 08:58:03.601 750-1132/? E/Watchdog: !@Sync 201
05-28 08:58:24.891 235-235/? E/SMD: DCD ON
05-28 08:58:27.891 235-235/? E/SMD: DCD ON
05-28 08:58:30.901 235-235/? E/SMD: DCD ON
05-28 08:58:33.601 750-1132/? E/Watchdog: !@Sync 202
05-28 08:58:33.901 235-235/? E/SMD: DCD ON
05-28 08:58:36.891 235-235/? E/SMD: DCD ON

Make sure you are not setting WindowManager.LayoutParams.FLAG_FULLSCREEN on any activity before the one that uses ZXingScannerView.

// WindowManager.LayoutParams.FLAG_FULLSCREEN suregetWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Remove the commented out lines if you have them on any activity.

QR Code scanner in Android using ZXing library with Example , Create an Android Project with an empty Activity called MainActivity. One is used to scan the QR Code and second is used to show result text  Therefore in this Android app tutorial, we’re going to demonstrate the process of scanning image of QR code Android at click of button using Zxing library. Let’s Get Started Create a new project in Android Studio.

Update your onResume() method

@Override
public void onResume() {
    super.onResume();

    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= android.os.Build.VERSION_CODES.M) {
        if (checkPermission()) {
            if(scannerView == null) {
                scannerView = new ZXingScannerView(this);
                setContentView(scannerView);
            }
            scannerView.setResultHandler(this);
            scannerView.startCamera();
        } else {
            requestPermission();
        }
    }else{ // below api 23
        scannerView.setResultHandler(this);
        scannerView.startCamera();
    }
}

Since Android 4.4.4 (API 19) doesn't need runtime permission, so you can just run startCamera() code

White screen in a fragment (zbar barcode scanning) · Issue #269 , I added a fragment to activity as usual, started camera similar to White screen in a fragment (zbar barcode scanning) #269 A device is Samsung Galaxy S4 running Android 5.0.1. When first time go to page, that using the scanner, there's no problem. scannerView = new ZXingScannerView(this); You may already seen QR Code many times. Whatsapp web also uses QR Code for login. QR Code stands for Quick Response Code. QR Code is actually a 2 dimensional bar code. A QR Code consist of black squares over a white background, and it can store some data, which can be read by camera or other imaging devices. Below you can see a sample QR Code.

I think the problem here is :RequestPermission Try this:

  private static final int ZXING_CAMERA_PERMISSION = 1123;
  public void requestPermisstion() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.CAMERA}, ZXING_CAMERA_PERMISSION);
    } else {
        //start camera or go to QR code activity 
    }
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case ZXING_CAMERA_PERMISSION:
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                Intent intent = new Intent(this, QRCodeActivity.class);
                startActivity(intent);

            } else {
                Toast.makeText(this, "Please grant camera permission to use the QR Scanner", Toast.LENGTH_SHORT).show();
            }
            return;
    }
}

Android QR Code Scanner App Tutorial Using ZXING Library, Choose Empty Activity and click next. In the next screen enter Activity Name as QrCodeScannerActivity and remember to check the Generate Layout Button and​  Step 6: Opening new activity in android studio. To open new activity in the android studio, click on File tab which is present at the left top bar. Now go to File->New->Activity->Empty Activity and place name of activity as ScanActivity.

Xamarin Android ZXing.Net.Mobile QR Code scanning blank screen , In my Xamarin Android project I am using ZXing.Net.Mobile QR Net.Mobile QR Code scanning blank screen after device lock and then unlock After back button pressed, App is navigated to previous activity view. Anyone  compile 'me.dm7.barcodescanner:zxing:1.9' Adding Functionality to Scan QR Code and Bar Code. Open QrCodeScannerActivity.java and declare the following imports variables. Please note that our activity implements the Interface ZXingScannerView.ResultHandler to be able to act as QR Code Scanner as well as Bar Code scanner. QrCodeScannerActivity.java

Implement Android QR Code Scanner Using ZXing Library in Kotlin , Learn to implement android QR Code Scanner Using ZXing library in kotlin, qr code scanner in activity and qr code scanner in fragment using zxing library. A QR Code consists of black squares arranged in a square grid on a white background that can be read by Then, select Empty Activity => click next => click finish. 5. Use the ZXing Barcode Scanner in an Android App. Barcodes and Quick Response (QR) codes are useful for storing short sequences of data that can be recognised by a variety of machines and devices. They are particularly good for stock control hence the universal use on packaging and for logistics.

Scan Barcode And QRcode Using Zxing Android Studio , scan barcode and qrcode using zxing android example tutorial guides you to scan barcode and read qrcode in android app using zxing library programmatically. that unique id from barcode logo on product box or from the computer screen. Now go to File->New->Activity->Empty Activity and place name of activity as  This is a simple android application which demonstrates how to develop a QR Code Scanner in android with code and output checking on real device. Watch it and learn it. keep subscribing. Thank you