Android Zxing change orientation to portrait

Solution 1:

After a lot of struggling, I found the problem, and I hope it will help someone in the future.

On initFromCameraParameters method in CameraConfigurationManager there is an assumption that the scan is ALWAYS in landscape mode, and therefor a fix when width < height. If You follow the steps in the question and remove this check, it works fine.

Solution 2:

As of zxing library:2.2.0 support for orientation change is inherent

Add/edit the following in manifest:

<activity
    android:name="com.journeyapps.barcodescanner.CaptureActivity"
    android:screenOrientation="fullSensor"
    tools:replace="screenOrientation" />

Set additional property at call to scanner :

IntentIntegrator integrator = new IntentIntegrator(this);

//allows portrait/landscape mode
integrator.setOrientationLocked(false);//"additional property"
integrator.initiateScan();

Reference link : https://github.com/journeyapps/zxing-android-embedded#changing-the-orientation

Solution 3:

Thank you for your answer!! it really helped me, one thing that I noticed is that at least on zxing 2.1 you need to pass "rotatedData" to buildLuminanceSource instead of just "data", the line end up like this:

PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height);

Hopefully this helps someone else!

Solution 4:

Well I made a small change in ProjectLibrary (xzing project) and able to change orientation landscape to portrait

In setDesiredCameraParameters method of class CameraConfigurationManager added

camera.setDisplayOrientation(90);

.. in my original project's AndroidManifest.xml file. I set screenOrientation = portrait and Its working fine on my ICS 4.0.3

   <activity
        android:name="com.google.zxing.client.android.CaptureActivity"
        android:configChanges="orientation|keyboardHidden"
        android:exported="false"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:windowSoftInputMode="stateAlwaysHidden" >
        <intent-filter>
            <action android:name="com.phonegap.plugins.barcodescanner.SCAN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>