Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Zxing in portrait mode?

Tags:

android

Currently zxing library supports only on landscape mode.For my app i need to use in portrait mode

like image 527
Kiran Babu Avatar asked Nov 04 '11 09:11

Kiran Babu


People also ask

Can Zxing scan QR code?

On click of button_scan_qr_code , CaptureActivity will start scanning using default camera. Once it scans any QR code, it sends back the result to onActivityResult the MainActivity . ZXing also provides online QR Code Generator. Enter the required fields, generate and scan it to get the results.

How does scanning area increase in Zxing size?

If you are calling this from another android app, use intent extras SCAN_WIDTH and SCAN_HEIGHT for this. If you happen to be using phonegap-plugin-barcodescanner (3.0. 0 or later), then passing the same intents like xxxxx. scan(onSuccessFunc,onFailFunc,{SCAN_HEIGHT:111,SCAN_WIDTH:222}) will produce the same result.


2 Answers

Here is the Solution for Portrait mode Scanning

first declare these two lines in your app level gradle file

implementation 'com.journeyapps:zxing-android-embedded:3.0.1@aar' implementation 'com.google.zxing:core:3.2.0' 

Define a button in your xml file and in Onclick Listener of button write below code in MainActivity java file

IntentIntegrator integrator = new IntentIntegrator(this);     integrator.setPrompt("Scan a barcode");     integrator.setCameraId(0);  // Use a specific camera of the device     integrator.setOrientationLocked(true);     integrator.setBeepEnabled(true);     integrator.setCaptureActivity(CaptureActivityPortrait.class);     integrator.initiateScan(); 

Write below code in your MainActivity java file after onCreate() method

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); if(result != null) {     if(result.getContents() == null) {         Log.d("MainActivity", "Cancelled scan");         Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();     } else {         Log.d("MainActivity", "Scanned");         st_scanned_result = result.getContents();         Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();      }   }  } 

then create a class with name CaptureActivityPortrait that extends CaptureActivity. The class looks like below

  package soAndSo(Your PackageName);    import com.journeyapps.barcodescanner.CaptureActivity;    public class CaptureActivityPortrait extends CaptureActivity {   } 

And Most Important declare your CaptureActivityPortrait in manifest file like below

<activity android:name=".CaptureActivityPortrait"         android:screenOrientation="sensorPortrait"         android:stateNotNeeded="true"         android:theme="@style/zxing_CaptureTheme"         android:windowSoftInputMode="stateAlwaysHidden"></activity> 
like image 79
Tara Avatar answered Sep 21 '22 13:09

Tara


Just check out issue for Use Zxing in portrait mode.

like image 35
Uttam Avatar answered Sep 22 '22 13:09

Uttam