-
[Android]바코드 or QR코드 읽기Programing Language/Android Studio(Java&Kotlin) 2019. 8. 26. 21:46728x90반응형
https://github.com/journeyapps/zxing-android-embedded
Adding aar dependency with Gradle
From version 3.6.0, only Android SDK 19+ is supported by default.
Add the following to your build.gradle file:
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
Hardware Acceleration
Hardware accelation is required since TextureView is used.
Make sure it is enabled in your manifest file:
<application android:hardwareAccelerated="true" ... >
Add this code to Activitiy
Customize options:
onCreate(){ // onCreate에 넣거나 버튼클릭이벤트 넣거나 IntentIntegrator integrator = new IntentIntegrator(this); integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES); integrator.setPrompt("Scan a barcode"); integrator.setCameraId(0); // Use a specific camera of the device integrator.setBeepEnabled(false); integrator.setBarcodeImageEnabled(true); integrator.initiateScan(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); if(result != null) { if(result.getContents() == null) { Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show(); } } else { super.onActivityResult(requestCode, resultCode, data); } }
위의 방법은 세로모드만 인식된다.
가로모드로 바코드를 찍고싶다면.
1.자바 클래스 추가
import com.journeyapps.barcodescanner.CaptureActivity; public class AnyOritationCaptureActivity extends CaptureActivity { }
2.Manifests 추가
<activity android:name=".JavaClass.AnyOritationCaptureActivity" android:screenOrientation="fullSensor" android:stateNotNeeded="true" android:theme="@style/zxing_CaptureTheme" android:windowSoftInputMode="stateAlwaysHidden"/>
3. IntentIntegrator 에
integrator.setCaptureActivity(AnyOritationCaptureActivity.class);
추가
애플은 사랑입니다!
]
728x90반응형'Programing Language > Android Studio(Java&Kotlin)' 카테고리의 다른 글
Android) 유용한 단축키(Mac)[펌] (0) 2020.04.12 [Android Studio] 인스타같은 이미지 필터 예제 (0) 2019.08.29 자바 for문을 이용하여 Map, Hash 값 꺼내기 (0) 2019.08.23 AlterDialog 코드 (0) 2019.08.13 (Android)앨범에서 이미지 가져올때 회전되는 문제 수정 하는방법 (0) 2019.06.04