All Products
Search
Document Center

Mobile Platform as a Service:Scan code parsing

Last Updated:Jan 27, 2026

This API lets you use the code scanning component on Android. Before calling the API, you must add the code scanning component to your project. Use the actionType parameter to retrieve the code value.

Using the scan API

AlipayJSBridge.call('scan', {
  type: 'bar',
  actionType: 'scan'
}, function(result) {
  alert(JSON.stringify(result));
});

Code example

Retrieve information from a QR code:

<h1>Click to scan and output the code information</h1>
<a href="#" class="btn read">Start scanning</a>
<script>
function ready(callback) {
  // If AlipayJSBridge is already injected, call the callback directly.
  if (window.AlipayJSBridge) {
    callback && callback();
  } else {
    // If not, listen for the injection event.
    document.addEventListener('AlipayJSBridgeReady', callback, false);
  }
}
ready(function() {
  document.querySelector('.read').addEventListener('click', function() {
    AlipayJSBridge.call('scan', {
      type: 'qr'
    }, function(result) {
      alert(JSON.stringify(result));
    });
  });
});
</script>

API

AlipayJSBridge.call('scan', {
  type, actionType, qrcode
}, fn);

Input parameters

Property

Type

Description

Required

Default value

type

String

You can scan QR codes and barcodes.

Yes

""

actionType

String

The type of operation. The value scan gets the code value.

N

"scan"

qrcode

String

The code value to use for the route operation type.

N

""

fn

function

The callback function that runs after the scan gets the code information.

N

-

Output parameters

The callback function is passed a result object containing the following parameters: result: {error, barCode, qrCode, cardNumber}.

Property

Type

Description

barCode

String

The bar code data from the scan.

qrCode

String

The QR code data from the scan.

error

int

Error code:

10: The user canceled.

11: The operation failed.