# uni.scanCode(OBJECT)

Call up the code scanning interface of the client, and return the corresponding result after the code scanning is successful.

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序、飞书小程序 QQ小程序 快手小程序 京东小程序
x

OBJECT parameter description

Parameter Name Type Required Description Platform Difference Description
onlyFromCamera Boolean 是否只能从相机扫码,不允许从相册选择图片 抖音小程序、百度小程序、支付宝小程序不支持此参数
scanType Array 扫码类型,参考下方scanType的合法值 抖音小程序不支持此参数
autoDecodeCharset Boolean No Whether to enable the automatic character encoding function, the default is No App
autoZoom Boolean No Whether to enable auto zoom, enabled by default Only supported by App-Android (3.5.4+)
barCodeInput Boolean No Whether to support manual barcode input Only supported by Feishu MiniApp(V3.14.0)
hideAlbum Boolean No Whether to hide the album (not allowed to select pictures from the album), only scan the code from the camera. The default value is false. Only supported by Alipay MiniApp
success Function No The callback of the successful interface call. For the return content, please refer to the return parameter description.
fail Function No Callback function for interface call failure (triggered when identification fails, user cancels, etc.)
complete Function No The callback function of the end of the interface call (it will be executed when the call succeeds or fails)

Legal value of scanType

value description
barCode one-dimensional code
qrCode QR code
datamatrix Data Matrix code
pdf417 PDF417 Barcode

success return parameter description

Parameter Description Platform Difference Description
result The content of the scanned code
scanType Type of scanned code App, WeChat MiniApp, Baidu MiniApp, QQ MiniApp, JD MiniApp, Alipay MiniApp
charSet The character set of the scanned code App, WeChat MiniApp, Baidu MiniApp(the character set scanned, only supports Android system), QQ MiniApp, Jingdong MiniApp
path When the scanned code is a legal QR code of the current application, this field will be returned, and the content is the path carried by the QR code. WeChat MiniApp, QQ MiniApp, Jingdong MiniApp
rawData raw data, base64 encoding WeChat MiniApp, QQ MiniApp, JD MiniApp, Alipay MiniApp
code Data obtained by scanning the code Alipay MiniApp
qrCode Return QR code data when scanning a QR code Alipay MiniApp
barCode Return barcode data when scanning a barcode Alipay MiniApp
imageChannel Source Alipay MiniApp

example

// Allow scanning codes from camera and album
uni.scanCode({
	success: function (res) {
		console.log('条码类型:' + res.scanType);
		console.log('条码内容:' + res.result);
	}
});

// Only allow scanning codes through the camera
uni.scanCode({
	onlyFromCamera: true,
	success: function (res) {
		console.log('条码类型:' + res.scanType);
		console.log('条码内容:' + res.result);
	}
});

// invoke barcode scanning
uni.scanCode({
	scanType: ['barCode'],
	success: function (res) {
		console.log('条码类型:' + res.scanType);
		console.log('条码内容:' + res.result);
	}
});

Tip