Here is the solution for Portrait mode Scanning
first declare these two lines at your application level gradle file
compile 'com.journeyapps:zxing-android-embedded:3.0.1@aar' compile 'com.google.zxing:core:3.2.0'
Define the button in your xml file and in the Onclick Listener of the button write the code below in the Java MainActivity 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();
Enter the code below into your Java MainActivity file after the 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 called CaptureActivityPortrait that extends CaptureActivity. Class looks lower
package soAndSo(Your PackageName); import com.journeyapps.barcodescanner.CaptureActivity; public class CaptureActivityPortrait extends CaptureActivity { }
And the most important thing is to declare your CaptureActivityPortrait in the manifest file, as shown below
<activity android:name=".CaptureActivityPortrait" android:screenOrientation="portrait" android:stateNotNeeded="true" android:theme="@style/zxing_CaptureTheme" android:windowSoftInputMode="stateAlwaysHidden"></activity>
Tara Apr 07 '17 at 10:58 on 2017-04-07 10:58
source share