Intent Integration
Overview
This section outlines the capabilities of the intent integration, which facilitates seamless integration with the Android Aladdin application. Intent integration provides a sophisticated registering model, enabling developers to efficiently receive and manage scanned data. With built-in functionalities for sharing data, developers gain a professional and adaptable solution for incorporating scanned data into their applications.
Intent Integration in Aladdin
-
Select the Intent option in the Integration UI of Aladdin application.
-
A UI will appear to enter the names for the barcode action, barcode data, label type and scan time extra name in their respective input fields. The input fields will be pre-populated with default names, but can be modified to fit your needs.
Below are the default values used in Aladdin app:
- Barcode event action name:
COM.DATALOGIC.ALADDINAPP.INTENT.ACTION_SEND_BAR_CODE_DATA
- Barcode data extra name:
COM.DATALOGIC.ALADDINAPP.EXTRA.BARCODE_DATA
- Barcode label type extra name:
COM.DATALOGIC.ALADDINAPP.EXTRA.BARCODE_CODE_TYPE
- Barcode scan time extra name:
COM.DATALOGIC.ALADDINAPP.EXTRA.BARCODE_SCAN_TIME
- Barcode event action name:
-
Click "Save". Now, whenever the CODiScan scans a barcode, the application will send a broadcast with the barcode event action name and intent extra names which you entered in step 2.
Client Application Implementation
Barcode event
To receive a barcode event in the client application, the client must implement a broadcast receiver with the action and extras names that you entered in the Aladdin application.
Example:
- Kotlin
- Java
class BarCodeReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if ("COM.DATALOGIC.ALADDINAPP.INTENT.ACTION_SEND_BAR_CODE_DATA" == intent.action) {
val data = intent.getStringExtra("COM.DATALOGIC.ALADDINAPP.EXTRA.BARCODE_DATA")
val codeType = intent.getStringExtra("COM.DATALOGIC.ALADDINAPP.EXTRA.BARCODE_CODE_TYPE")
val scanTime = intent.getLongExtra("COM.DATALOGIC.ALADDINAPP.EXTRA.BARCODE_SCAN_TIME", 0L)
Toast.makeText(context, data, Toast.LENGTH_SHORT).show()
}
}
}
class BarCodeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("COM.DATALOGIC.ALADDINAPP.INTENT.ACTION_SEND_BAR_CODE_DATA" == intent.getAction()) {
String data = intent.getStringExtra("COM.DATALOGIC.ALADDINAPP.EXTRA.BARCODE_DATA")
String codeType = intent.getStringExtra("COM.DATALOGIC.ALADDINAPP.EXTRA.BARCODE_CODE_TYPE")
long scanTime = intent.getLongExtra("COM.DATALOGIC.ALADDINAPP.EXTRA.BARCODE_SCAN_TIME", 0L)
Toast.makeText(context, data, Toast.LENGTH_SHORT).show()
}
}
}
Define an IntentFilter
for the specified actions:
- Kotlin
- Java
val barCodeReceiver = BarCodeReceiver()
val barCodeIntent = IntentFilter("COM.DATALOGIC.ALADDINAPP.INTENT.ACTION_SEND_BAR_CODE_DATA")
BarCodeReceiver barCodeReceiver = new BarCodeReceiver();
IntentFilter barCodeIntent = new IntentFilter("COM.DATALOGIC.ALADDINAPP.INTENT.ACTION_SEND_BAR_CODE_DATA");
Register the broadcast receiver instance, the usual place for this call would be in the onCreate
method of a Service or Activity class:
- Kotlin
- Java
registerReceiver(barCodeReceiver, barCodeIntent)
registerReceiver(barCodeReceiver, barCodeIntent);
Connection status event
You can get the scanner connection state by registering a receiver for the action name com.datalogic.aladdinapp.intent.ACTION_SEND_SCANNER_STATE
with extra com.datalogic.aladdinapp.extra.SCANNER_STATE
Implement a broadcast receiver:
- Kotlin
- Java
class ScannerStateReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if ("com.datalogic.aladdinapp.intent.ACTION_SEND_SCANNER_STATE" == intent.action) {
val connected =
intent.getBooleanExtra("com.datalogic.aladdinapp.extra.SCANNER_STATE", false)
if (connected) {
Toast.makeText(context, "Connected to scanner", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(context, "Disconnected from scanner", Toast.LENGTH_SHORT).show()
}
}
}
}
class ScannerStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("com.datalogic.aladdinapp.intent.ACTION_SEND_SCANNER_STATE" == intent.getAction()) {
boolean connected =
intent.getBooleanExtra("com.datalogic.aladdinapp.extra.SCANNER_STATE", false);
if (connected) {
Toast.makeText(context, "Connected to scanner", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Disconnected from scanner", Toast.LENGTH_SHORT).show();
}
}
}
}
Define an IntentFilter
for the specified actions:
- Kotlin
- Java
val scanStateReceiver = ScannerStateReceiver()
val connectionStateIntent =
IntentFilter("com.datalogic.aladdinapp.intent.ACTION_SEND_SCANNER_STATE")
ScannerStateReceiver scannerStateReceiver = new ScannerStateReceiver();
IntentFilter connectionStateIntent =
IntentFilter("com.datalogic.aladdinapp.intent.ACTION_SEND_SCANNER_STATE");
Register the broadcast receiver instance, the usual place for this call would be in the onCreate
method of a Service or Activity class:
- Kotlin
- Java
registerReceiver(scanStateReceiver, connectionStateIntent)
registerReceiver(scanStateReceiver, connectionStateIntent);
Get Latest Scan Data
You can get the latest scanned barcode data by sending the broadcast below. The Aladdin application will send the barcode details under the defined action name within Aladdin.
Default: COM.DATALOGIC.ALADDINAPP.INTENT.ACTION_SEND_BAR_CODE_DATA
- Kotlin
- Java
val intent = Intent("com.datalogic.aladdinapp.intent.ACTION_GET_LATEST_SCAN_DATA")
sendBroadcast(intent)
Intent intent = new Intent("com.datalogic.aladdinapp.intent.ACTION_GET_LATEST_SCAN_DATA");
sendBroadcast(intent);
Get Connection State
You can get the scanner connection state by sending the broadcast below. The Aladdin application will send the connection details in the following action: com.datalogic.aladdinapp.intent.ACTION_SEND_SCANNER_STATE
- Kotlin
- Java
val intent = Intent("com.datalogic.aladdinapp.intent.ACTION_GET_SCANNER_STATE")
sendBroadcast(intent)
Intent intent = new Intent("com.datalogic.aladdinapp.intent.ACTION_GET_SCANNER_STATE");
sendBroadcast(intent);
Intent Sample Client
The Aladdin intent client is a purposefully crafted sample application designed to showcase the dynamic capabilities of the Intent integration.
The client APK and source code can be found in the Aladdin samples repository on Github.
-
Select Intent as the integration method within the Aladdin app.
-
The Intent setting UI will appear with some pre-populated fields. You can change the content of each input text field (or leave the default) and tap the "Save" button to confirm. Please, note that each field should contain unique entries; the same data should not be repeated.
-
Open the Intent client application.
-
Tap the "Register to Aladdin" button.
-
A pop-up will appear with 4 pre-populated input fields. The name of each field must be the same that you entered in step 2.
-
You can now scan barcodes with your CODiScan device. The barcode details will be displayed in a toast message in the client application.
-
You can also tap "Get latest barcode" and retrieve the latest scanned barcode data.
-
To check the scanner status, tap "Get scanner status".
-
To unregister from the Aladdin application, tap "Unregister from Aladdin".
Notes:
- The client can register to Aladdin irrespective of any integration method selected in the application, but it cannot receive barcode data or connection state if Intent is not selected as the integration method within Aladdin.
- If Intent is selected as the integration method, but the action and intent extras do not match between Aladdin and the client application, you will not be able to receive barcode events in the client app. You can only get the scanner status. You can unregister from Aladdin and then register anew with the same key values entered in the Aladdin app.
- If Intent is not selected as integration method in the Aladdin app and you try to register to the Intent client application, registration will be successful, but the "Get latest barcode" and the "Get scanner status" buttons will be disabled and you will not be able to receive new barcode data scanned by the CODiScan.
- User input for barcode extra names (barcode data, label type, and scan time) should be unique.
- If all entries are equal and unique in both client and Aladdin app, you will get the barcode details in the toast message.