Package com.gluonhq.attach.barcodescan
Interface BarcodeScanService
-
- All Known Implementing Classes:
AndroidBarcodeScanService
,DummyBarcodeScanService
,IOSBarcodeScanService
public interface BarcodeScanService
The barcode scanner can be used to scan barcodes of different types. The implementation of the service will typically open the device's camera to scan for a barcode. When a valid barcode could be detected and scanned, the string value that is represented by the barcode will be returned as a result.Example
BarcodeScanService.create().ifPresent(service -> { service.resultProperty().addListener((obs, ov, nv) -> System.out.printf("Scanned result: %s", nv.getResult())); service.asyncScan(); });
Requirements
The service requires the following changes on Android and iOS.
However, these are handled automatically by the GluonFX plugin, when used.
Android Configuration
The permission
android.permission.CAMERA
needs to be added together with the followingactivity
configuration that handles the SCAN intent of the BarcodeScanService.<manifest ...> <uses-permission android:name="android.permission.CAMERA"/> ... <application ...> ... <activity android:name="com.gluonhq.helloandroid.zxing.CaptureActivity" android:screenOrientation="sensorLandscape" android:clearTaskOnLaunch="true" android:stateNotNeeded="true" android:windowSoftInputMode="stateAlwaysHidden"> <intent-filter> <action android:name="com.gluonhq.attach.barcodescan.android.SCAN"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> <activity android:name="com.gluonhq.impl.attach.plugins.android.PermissionRequestActivity" /> </application> </manifest>
iOS Configuration
The following keys are required:
<key>NSCameraUsageDescription</key> <string>Reason to use Camera Service (iOS 10+)</string>
- Since:
- 3.0.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
asyncScan()
Starts up the scanner functionality (commonly provided via the camera), and then parsed by Attach to determine the string the barcode represents.void
asyncScan(java.lang.String title, java.lang.String legend, java.lang.String resultText)
Starts up the scanner functionality (commonly provided via the camera), and then parsed by Attach to determine the string the barcode represents.static java.util.Optional<BarcodeScanService>
create()
Returns an instance ofBarcodeScanService
.javafx.beans.property.ReadOnlyStringProperty
resultProperty()
A read-only property containing the result of the scan.java.util.Optional<java.lang.String>
scan()
Deprecated.This method has been deprecated in favour ofasyncScan()
.java.util.Optional<java.lang.String>
scan(java.lang.String title, java.lang.String legend, java.lang.String resultText)
Deprecated.This method has been deprecated in favour ofasyncScan(String, String, String)
.
-
-
-
Method Detail
-
create
static java.util.Optional<BarcodeScanService> create()
Returns an instance ofBarcodeScanService
.- Returns:
- An instance of
BarcodeScanService
.
-
asyncScan
void asyncScan()
Starts up the scanner functionality (commonly provided via the camera), and then parsed by Attach to determine the string the barcode represents.- Since:
- 4.0.16
-
scan
@Deprecated java.util.Optional<java.lang.String> scan()
Deprecated.This method has been deprecated in favour ofasyncScan()
.Starts up the scanner functionality (commonly provided via the camera), in a blocking way, and then parsed by Attach to determine the string the barcode represents.- Returns:
- Returns an Optional containing the parsed string. The Optional may be empty if the String fails to be parsed for any reason, or if the user cancels the operation.
-
asyncScan
void asyncScan(java.lang.String title, java.lang.String legend, java.lang.String resultText)
Starts up the scanner functionality (commonly provided via the camera), and then parsed by Attach to determine the string the barcode represents.- Parameters:
title
- The title of the scan view. If null or empty nothing will be displayed.legend
- An explanatory message displayed in the scan view. If null or empty nothing will be displayed.resultText
- The text to display when the scan ends successfully, before the scanned text. If empty or null, the result won't be shown.- Since:
- 4.0.16
-
scan
@Deprecated java.util.Optional<java.lang.String> scan(java.lang.String title, java.lang.String legend, java.lang.String resultText)
Deprecated.This method has been deprecated in favour ofasyncScan(String, String, String)
.Starts up the scanner functionality (commonly provided via the camera), in a blocking way, and then parsed by Attach to determine the string the barcode represents.- Parameters:
title
- The title of the scan view. If null or empty nothing will be displayed.legend
- An explanatory message displayed in the scan view. If null or empty nothing will be displayed.resultText
- The text to display when the scan ends successfully, before the scanned text. If empty or null, the result won't be shown.- Returns:
- Returns an Optional containing the parsed string. The Optional may be empty if the String fails to be parsed for any reason, or if the user cancels the operation.
- Since:
- 3.8.0
-
resultProperty
javafx.beans.property.ReadOnlyStringProperty resultProperty()
A read-only property containing the result of the scan.- Returns:
- a read-only object property containing a string with the barcode or QR code scan
- Since:
- 4.0.16
-
-