FX325 Imager (Android 10)
The FX325 has a built-in BarcodeImager to scan 1D and 2D barcodes. The barcode reader can be used keyboard emulation mode : Accessible directly from the Android settings > Laser > Laser Scanner Service.
In order to use the barcode within you app, you also need to add following permissions inside your AndroidManifest.xml:
<uses-permission android:name="android.permission.BARCODE_SCANNER" /> <uses-permission android:name="android.permission.CAMERA" />
Usage in keyboard emulation mode
- To activate the laser, you can use physical button on the left side of the device.
- The result of the scan is displayed directly on the screen where your app has the focus (ex: Android TextField) or by catching the "OnKeyUp" event (cf. sample code)
- The beam turns off after a code is read or after 10 seconds.
Demo application using an EditText
Alternative without using an EditText
public class MainActivity extends AppCompatActivity { private StringBuilder barcode; private TextView tvBarcode; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvBarcode = findViewById(R.id.tvBarcode); barcode = new StringBuilder(); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_SHIFT_LEFT && keyCode != KeyEvent.KEYCODE_F1 && keyCode != KeyEvent.KEYCODE_F2) { if (keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(TAG, "decoded text = " + barcode); tvBarcode.setText(barcode); barcode = new StringBuilder(); } else { barcode.append((char)event.getUnicodeChar()); } } return true; } }