This article introduces the operation steps of accessing the Scan SDK in Android.
Since June 28, 2020, Alibaba Cloud stopped maintaining the baseline 10.1.32 for mPaaS. Upgrade your baseline to version 10.1.60, 10.1.68 or 10.2.3. The Scan component supports two access modes, they are native AAR mode and component-based mode (Portal & Bundle) . This topic describes how to use the scan function of the baseline version of 10.1.68, 10.1.60 and 10.2.3. Scan supports multi-code recognition in full-screen mode starting from the mPaaS baseline version of 10.1.68.33. Scan has added the function of AI recognizing small codes and automatically zooming in starting from the mPaaS baseline version of 10.2.3.
Prerequisites
If you want to connect the component to the mPaaS based on the native AAR mode, you need to first complete the prerequisites and the subsequent steps. For more information, see Add mPaaS to your project.
If you want to connect the component to the mPaaS based on components, you need to first complete the Component-based access procedure.
Add the SDK
10.2.3
If you want to use AI to recognize small codes and automatically zoom in, please install the Scan AI component.
Native AAR mode
In your project, install the Scan/Scan AI component on the Component Management (AAR) page. For more information, see AAR component management .
Component-based mode
In your Portal and Bundle projects, install the Scan/Scan AI component on the Component Management page. For more information, see Manage component dependencies.
10.1.68/10.1.60
Native AAR mode
In your project, install the Scan component on the Component Management (AAR) page. For more information, see AAR component management .
Component-based mode
In your Portal and Bundle projects, install the Scan component on the Component Management page. For more information, see Manage component dependencies.
Use the scan function
10.2.3/10.1.68
Use the full-screen scan code function
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 recognized", Toast.LENGTH_SHORT).show();
((Activity) context).finish();
// Returning true means that the callback has been consumed and no need to call back again.
return true;
}
});
Use the window scan code function
Call the scan function of the baseline 10.1.68 (old standard UI). If it failed, you will directly return to the scan page. If it succeeded, you will obtain URL information of 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) {
// In the scan page, click the physical back button or the back button in the upper left corner.
return;
}
// Note: this callback is executed in the child thread.
runOnUiThread(new Runnable() {
@Override
public void run() {
if (result == null || result.getData() == null) {
// Scan failed.
return;
}
// Scanned.
String url = result.getData().toString();
}
});
}
});
10.1.60
Call the scan function of the baseline 10.1.60. If it failed, you will directly return to the scan page. If it succeeded, you will obtain the URL information of 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) {
// In the scan page, click the physical back button or the back button in the upper left corner.
return;
}
// Note: this callback is executed in the child thread.
runOnUiThread(new Runnable() {
@Override
public void run() {
if (result == null || result.getData() == null) {
// Scan failed.
return;
}
// Scanned.
String url = result.getData().toString();
}
});
}
});