All Products
Search
Document Center

Quick start

Last Updated: May 21, 2021
Important: Since June 28, 2020, Alibaba Cloud stopped maintaining the baseline 10.1.32 for mPaaS. Upgrade your baseline to version 10.1.60 or 10.1.68.

The Scan component supports three access modes, they are native AAR mode, mPaaS Inside mode, and component-based mode (Portal & Bundle) . This topic describes how to use the scan function of the baselines 10.1.68 and 10.1.60.

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 the mPaaS Inside mode, you need to first complete the mPaaS Inside access procedure.
  • 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

Native AAR mode

In your project, install the Scan component on the Component Management (AAR) page. For more information, see AAR component management

mPaaS Inside mode

In your project, install the Scan component on the Component Management page.
For more information, see Manage component dependencies.

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.1.68

Call the scan function of the baseline 10.1.68. If it failed, you will directly return to the scan page. If it succeeded, you will obtain URL information of the QR code.

  1. ScanRequest scanRequest = new ScanRequest();
  2. scanRequest.setScanType(ScanRequest.ScanType.QRCODE);
  3. MPScan.startMPaasScanActivity(this, scanRequest, new ScanCallback() {
  4. @Override
  5. public void onScanResult(final boolean isProcessed, final Intent result) {
  6. if (!isProcessed) {
  7. // In the scan page, click the physical back button or the back button in the upper left corner.
  8. return;
  9. }
  10. // Note: this callback is executed in the child thread.
  11. runOnUiThread(new Runnable() {
  12. @Override
  13. public void run() {
  14. if (result == null || result.getData() == null) {
  15. // Scan failed.
  16. return;
  17. }
  18. // Scanned.
  19. String url = result.getData().toString();
  20. }
  21. });
  22. }
  23. });

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.

  1. ScanService service = LauncherApplicationAgent
  2. .getInstance().getMicroApplicationContext()
  3. .findServiceByInterface(ScanService.class.getName());
  4. ScanRequest scanRequest = new ScanRequest();
  5. scanRequest.setScanType(ScanRequest.ScanType.QRCODE);
  6. service.scan(this, scanRequest, new ScanCallback() {
  7. @Override
  8. public void onScanResult(boolean isProcessed, final Intent result) {
  9. if (!isProcessed) {
  10. // In the scan page, click the physical back button or the back button in the upper left corner.
  11. return;
  12. }
  13. // Note: this callback is executed in the child thread.
  14. runOnUiThread(new Runnable() {
  15. @Override
  16. public void run() {
  17. if (result == null || result.getData() == null) {
  18. // Scan failed.
  19. return;
  20. }
  21. // Scanned.
  22. String url = result.getData().toString();
  23. }
  24. });
  25. }
  26. });