This topic describes how to integrate the Scan SDK for Android.
Note Starting from June 28, 2020, mPaaS no longer maintains the 10.1.32 baseline. Upgrade to the 10.1.60, 10.1.68, or 10.2.3 baseline. Scan supports two connection types: native AAR and component-based (Portal&Bundle). This topic describes how to use the scan feature with the 10.2.3, 10.1.68, and 10.1.60 baselines. Starting from the mPaaS 10.1.68.33 baseline, Scan supports multi-code detection in full-screen mode. The mPaaS 10.2.3 baseline adds a feature that uses AI to detect and automatically magnify small codes. |
Prerequisites
If you use the native AAR connection type, you must complete the steps in Add mPaaS to your project.
If you use the component-based connection type, you must complete the Component-based integration process.
Add the SDK
10.2.3
To use the feature that uses AI to detect and automatically magnify small codes, you must install the Scan AI component.
Native AAR
Install the Scan/Scan AI component in your project using AAR Component Management. For more information, see Manage AAR components.
Component-based
In the Portal and Bundle projects, install the Scan/Scan AI component using Component Management. For more information, see Manage component dependencies.
10.1.68/10.1.60
Native AAR
Install the Scan component in your project using AAR Component Management. For more information, see Manage AAR components.
Component-based
In the Portal and Bundle projects, install the Scan component using Component Management. For more information, see Manage component dependencies.
Use the scan feature
10.2.3/10.1.68
Use the full-screen scan feature
ScanRequest scanRequest = new ScanRequest();
MPScan.startMPaasScanFullScreenActivity(this, scanRequest, new MPScanCallbackAdapter() {
@Override
public boolean onScanFinish(final Context context, MPScanResult mpScanResult, final MPScanStarter mpScanStarter) {
Toast.makeText(getApplicationContext(),
mpScanResult != null ? mpScanResult.getText() : "No code detected", Toast.LENGTH_SHORT).show();
((Activity) context).finish();
// Return true to indicate that the callback is consumed and does not need to be called again.
return true;
}
});Use the window scan feature
On the mPaaS 10.1.68 baseline, you can use the window scan feature (old standard UI). If the scan fails, the system returns to the scan interface. If the scan is successful, the system retrieves the URL from the QR code.
ScanRequest scanRequest = new ScanRequest();
scanRequest.setScanType(ScanRequest.ScanType.QRCODE);
MPScan.startMPaasScanActivity(this, scanRequest, new ScanCallback() {
@Override
public void onScanResult(final boolean isProcessed, final Intent result) {
if (!isProcessed) {
// The physical Back button or the Back button in the upper-left corner of the scan interface is tapped.
return;
}
// Note: This callback is executed in a subthread.
runOnUiThread(new Runnable() {
@Override
public void run() {
if (result == null || result.getData() == null) {
// The scan failed.
return;
}
// The scan is successful.
String url = result.getData().toString();
}
});
}
});10.1.60
On the 10.1.60 baseline, you can use the scan feature. If the scan fails, the system returns to the scan interface. If the scan is successful, the system retrieves the URL from the QR code.
ScanService service = LauncherApplicationAgent
.getInstance().getMicroApplicationContext()
.findServiceByInterface(ScanService.class.getName());
ScanRequest scanRequest = new ScanRequest();
scanRequest.setScanType(ScanRequest.ScanType.QRCODE);
service.scan(this, scanRequest, new ScanCallback() {
@Override
public void onScanResult(boolean isProcessed, final Intent result) {
if (!isProcessed) {
// The physical Back button or the Back button in the upper-left corner of the scan interface is tapped.
return;
}
// Note: This callback is executed in a subthread.
runOnUiThread(new Runnable() {
@Override
public void run() {
if (result == null || result.getData() == null) {
// The scan failed.
return;
}
// The scan is successful.
String url = result.getData().toString();
}
});
}
});