Skip to content

Commit 50b27ce

Browse files
committed
adding qr code scanning capabilitiies
1 parent 4d9c42b commit 50b27ce

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

AI_MultiBarcodes_Capture/src/main/java/com/zebra/ai_multibarcodes_capture/settings/SettingsActivity.java

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
import com.zebra.ai_multibarcodes_capture.helpers.LogUtils;
3838
import com.zebra.ai_multibarcodes_capture.managedconfig.ManagedConfigurationReceiver;
3939
import com.zebra.ai_multibarcodes_capture.models.LanguageItem;
40+
import com.zebra.datawedgeprofileenums.INT_E_DELIVERY;
41+
import com.zebra.datawedgeprofileenums.MB_E_CONFIG_MODE;
42+
import com.zebra.datawedgeprofileenums.SC_E_SCANNER_IDENTIFIER;
43+
import com.zebra.datawedgeprofileintents.DWProfileBaseSettings;
44+
import com.zebra.datawedgeprofileintents.DWProfileCommandBase;
45+
import com.zebra.datawedgeprofileintents.DWProfileSetConfigSettings;
46+
import com.zebra.datawedgeprofileintents.DWScanReceiver;
47+
import com.zebra.datawedgeprofileintents.DWScannerPluginDisable;
48+
import com.zebra.datawedgeprofileintents.DWScannerPluginEnable;
49+
import com.zebra.datawedgeprofileintentshelpers.CreateProfileHelper;
4050

4151
import androidx.activity.EdgeToEdge;
4252
import androidx.appcompat.app.AppCompatActivity;
@@ -46,6 +56,7 @@
4656
import androidx.core.view.ViewCompat;
4757
import androidx.core.view.WindowInsetsCompat;
4858

59+
import java.util.HashMap;
4960
import java.util.List;
5061

5162
import static com.zebra.ai_multibarcodes_capture.helpers.Constants.*;
@@ -85,6 +96,9 @@ public class SettingsActivity extends AppCompatActivity {
8596
private CheckBox cbUK_POSTAL, cbUPC_A, cbUPC_E, cbUPCE1, cbUSPLANET, cbUSPOSTNET;
8697
private CheckBox cbUS4STATE, cbUS4STATE_FICS;
8798

99+
private DWScanReceiver mScanReceiver;
100+
101+
88102
// BroadcastReceiver to listen for managed configuration reload requests
89103
private BroadcastReceiver reloadPreferencesReceiver = new BroadcastReceiver() {
90104
@Override
@@ -308,6 +322,12 @@ public void onClick(View view) {
308322
finish();
309323
}
310324
});
325+
326+
// Create Datawedge profile
327+
createDataWedgeProfile();
328+
329+
// Initialize receiver
330+
initializeScanReceiver();
311331
}
312332

313333
@Override
@@ -320,6 +340,10 @@ protected void onResume() {
320340
IntentFilter filter = new IntentFilter(ManagedConfigurationReceiver.ACTION_RELOAD_PREFERENCES);
321341
registerReceiver(reloadPreferencesReceiver, filter, RECEIVER_NOT_EXPORTED);
322342
LogUtils.d(TAG, "Registered BroadcastReceiver for managed configuration changes");
343+
344+
enableDataWedgePlugin();
345+
mScanReceiver.startReceive();
346+
323347
}
324348

325349
@Override
@@ -334,6 +358,8 @@ protected void onPause() {
334358
// Receiver was not registered, ignore
335359
LogUtils.d(TAG, "BroadcastReceiver was not registered, ignoring unregister attempt");
336360
}
361+
mScanReceiver.stopReceive();
362+
disableDatawedgePlugin();
337363
}
338364

339365
private void loadPreferences()
@@ -1048,4 +1074,101 @@ private void configureSystemBars() {
10481074
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
10491075
}
10501076
}
1077+
1078+
private void createDataWedgeProfile()
1079+
{
1080+
DWProfileSetConfigSettings settings = new DWProfileSetConfigSettings()
1081+
{{
1082+
mProfileName = SettingsActivity.this.getPackageName();
1083+
mTimeOutMS = 5000;
1084+
MainBundle.APP_LIST = new HashMap<>();
1085+
MainBundle.APP_LIST.put(SettingsActivity.this.getPackageName(), null);
1086+
MainBundle.CONFIG_MODE = MB_E_CONFIG_MODE.CREATE_IF_NOT_EXIST;
1087+
IntentPlugin.intent_action = SettingsActivity.this.getPackageName() + ".RECVR";
1088+
IntentPlugin.intent_category = "android.intent.category.DEFAULT";;
1089+
IntentPlugin.intent_output_enabled = true;
1090+
IntentPlugin.intent_delivery = INT_E_DELIVERY.BROADCAST;
1091+
KeystrokePlugin.keystroke_output_enabled = false;
1092+
ScannerPlugin.scanner_selection_by_identifier = SC_E_SCANNER_IDENTIFIER.AUTO;
1093+
ScannerPlugin.scanner_input_enabled = true;
1094+
ScannerPlugin.Decoders.decoder_qrcode = true;
1095+
ScannerPlugin.Decoders.decoder_ean8 = false;
1096+
ScannerPlugin.Decoders.decoder_ean13 = false;
1097+
ScannerPlugin.Decoders.decoder_aztec = false;
1098+
ScannerPlugin.Decoders.decoder_micropdf = false;
1099+
}};
1100+
1101+
CreateProfileHelper.createProfile(SettingsActivity.this, settings, new CreateProfileHelper.CreateProfileHelperCallback() {
1102+
@Override
1103+
public void onSuccess(String profileName) {
1104+
1105+
}
1106+
1107+
@Override
1108+
public void onError(String profileName, String error, String errorMessage) {
1109+
1110+
}
1111+
1112+
@Override
1113+
public void ondebugMessage(String profileName, String message) {
1114+
}
1115+
});
1116+
1117+
}
1118+
1119+
private void initializeScanReceiver()
1120+
{
1121+
mScanReceiver = new DWScanReceiver(this,
1122+
SettingsActivity.this.getPackageName() + ".RECVR",
1123+
"android.intent.category.DEFAULT",
1124+
false,
1125+
new DWScanReceiver.onScannedData() {
1126+
@Override
1127+
public void scannedData(String source, String data, String symbology) {
1128+
if(symbology.equalsIgnoreCase("QRCODE"))
1129+
{
1130+
1131+
}
1132+
}
1133+
});
1134+
}
1135+
1136+
private void enableDataWedgePlugin()
1137+
{
1138+
DWScannerPluginEnable dwpluginenable = new DWScannerPluginEnable(this);
1139+
DWProfileBaseSettings settings = new DWProfileBaseSettings()
1140+
{{
1141+
mProfileName = SettingsActivity.this.getPackageName();
1142+
}};
1143+
1144+
dwpluginenable.execute(settings, new DWProfileCommandBase.onProfileCommandResult() {
1145+
@Override
1146+
public void result(String profileName, String action, String command, String result, String resultInfo, String commandidentifier) {
1147+
}
1148+
1149+
@Override
1150+
public void timeout(String profileName) {
1151+
1152+
}
1153+
});
1154+
}
1155+
1156+
private void disableDatawedgePlugin()
1157+
{
1158+
DWScannerPluginDisable dwplugindisable = new DWScannerPluginDisable(this);
1159+
DWProfileBaseSettings settings = new DWProfileBaseSettings()
1160+
{{
1161+
mProfileName = SettingsActivity.this.getPackageName();
1162+
}};
1163+
1164+
dwplugindisable.execute(settings, new DWProfileCommandBase.onProfileCommandResult() {
1165+
@Override
1166+
public void result(String profileName, String action, String command, String result, String resultInfo, String commandidentifier) {
1167+
}
1168+
@Override
1169+
public void timeout(String profileName) {
1170+
1171+
}
1172+
});
1173+
}
10511174
}

0 commit comments

Comments
 (0)