智慧屏 安装 app如何提升家庭娱乐与教育体验的关键工具
618
2022-10-29
PhotoBarcode - 易于使用的库在Android应用程序中拍照或扫描条形码
PhotoBarcode
Easy to use library to take picture or scanning barcodes in the Android application.
Dependency
Add this in your root build.gradle file (not your module build.gradle file):
allprojects { repositories { maven { url "https://jitpack.io" } }}
Then, add the library to your module build.gradle
dependencies { implementation 'com.github.ivan200:PhotoBarcode:1.1.1'}
Usage
To taking picture
fabPicture.setOnClickListener(view -> { final PhotoBarcodeScanner photoBarcodeScanner = new PhotoBarcodeScannerBuilder() .withActivity(this) .withTakingPictureMode() .withPictureListener(file -> { imageView.setImageURI(Uri.fromFile(file)); }) .build(); photoBarcodeScanner.start();});
To scan a barcode
fabBarcode.setOnClickListener(view -> { final PhotoBarcodeScanner photoBarcodeScanner = new PhotoBarcodeScannerBuilder() .withActivity(this) .withResultListener((Barcode barcode) -> { textView.setText(barcode.rawValue); }) .build(); photoBarcodeScanner.start();});
That's it!
Or you can customize the builder with a lot more options:
Additional parameters with default values:
Flags for both modes:
.withCameraFullScreenMode(false) //Mode of camera preview: FullScreen - 16/9 with horizontal crop, or otherwise 4/3 with screen fit.withRequestedFps(25.0f) //Fps in preview of picture..withSoundEnabled(true) //Enables or disables a sound whenever picture taken or a barcode is scanned.withAutoFocus(true) //Enables or disables auto focusing on the camera.withFocusOnTap(true) //Allow focus picture when user tap on screen.withFlashMode(FlashMode) //Setup default flash mode before open camera.withFlashListener(Consumer
Flags for picture mode:
.withTakingPictureMode() //Activate takingPicture mode instead of taking barcode (barcode mode is default).withPreviewImage(true) //Allow preview image and redo it before it returned.withPictureListener(Consumer
Flags for barcode mode:
.withCenterTracker(false) //Enables the default center tracker (white square in screen).withResultListener(Consumer
Notice
If you want the library to fully handle requests permissions, you need to pass onActivityResult and onRequestPermissionsResult to PhotoBarcodeScanner, for example like this:
@Overridepublic void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); photoBarcodeScanner.onRequestPermissionsResult(requestCode, permissions, grantResults);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); photoBarcodeScanner.onActivityResult(requestCode, resultCode, data);}
Or you can manage permissions by yourself before calling photoBarcodeScanner.start();
Screenshots
Developed By
Zakharov Ivan79067180651@ya.ruDonate with Paypal
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~