条形码扫描
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。

利用机器学习套件的条形码扫描 API,您可以读取使用大多数标准条形码格式编码的数据。条形码扫描在设备上进行,不需要网络连接。
条形码是将现实世界中的信息传递到应用的一种便捷方式。具体而言,在使用二维码等 2D 格式时,您可以对结构化数据(例如联系信息或 Wi-Fi 网络凭据)进行编码。由于机器学习套件可以自动识别和解析此数据,因此当用户扫描条形码时,您的应用可以智能地做出响应。
对于不需要自定义界面的用户,我们建议您使用 Google 扫码器。扫码器 API 使用与标准条形码扫描 API 相同的推断模型,但只会返回最集中的条形码,从而提供更快、更一致的体验。Google 扫码器也更安全且无需权限,并且不需要与摄像头相关的实现或权限。
iOS
Android
Google 扫码器
主要功能
- 读取大多数标准格式
- 线性格式:Codabar、Code 39、Code 93、Code 128、EAN-8、EAN-13、ITF、UPC-A、UPC-E
- 2D 格式:Aztec、Data Matrix、PDF417、二维码
- 自动格式检测
- 一次扫描所有支持的条形码格式,而无需指定想要的格式,或者将检测器限制为仅扫描您感兴趣的格式,以提高扫描速度。
- 提取结构化数据
- 系统会自动解析使用某种受支持的 2D 格式存储的结构化数据。支持的信息类型包括网址、联系信息、日历活动、电子邮件地址、电话号码、短信提示、ISBN、Wi-Fi 连接信息、地理位置和 AAMVA 标准驱动程序信息。
- 适用于任何屏幕方向
- 无论条形码的方向如何(正置、倒置或侧置),系统都可以识别并扫描条形码。
- 在设备上运行
- 条形码扫描完全在设备上执行,不需要网络连接。
请注意,此 API 无法识别以下形式的条形码:
- 只包含一个字符的一维条形码
- ITF 格式的条形码少于 6 个字符,并且由于缺少校验和而已知该格式不稳定
- 使用 FNC2、FNC3 或 FNC4 编码的条形码
- 在 ECI 模式下生成的二维码
此 API 每次调用 API 时最多只能识别 10 个条形码。
示例结果
|
结果 |
角 |
(49,125)、(172,125)、(172,160)、(49,160) |
原始值 |
2404105001722 |
|
|
结果 |
角 |
(87,87) (612,87) (612,612) (87,612) |
原始值 |
WIFI:S:SB1Guest;P:12345;T:WEP;; |
Wi-Fi 信息 |
SSID |
SB1Guest |
密码 |
12345 |
类型 |
WEP |
|
|
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eML Kit's Barcode Scanning API reads data from most standard barcode formats, including linear and 2D formats, without needing an internet connection.\u003c/p\u003e\n"],["\u003cp\u003eIt automatically detects and parses structured data like contact info, WiFi credentials, and more from supported 2D formats, enabling intelligent app responses.\u003c/p\u003e\n"],["\u003cp\u003eThe API works offline, recognizing barcodes in any orientation, and the Google Code Scanner offers a faster, safer, and permissionless option for basic scanning needs.\u003c/p\u003e\n"],["\u003cp\u003eWhile it supports a wide range of formats and data types, the API has limitations regarding certain 1D barcodes, ITF formats, and QR codes with specific encodings, recognizing a maximum of 10 barcodes per call.\u003c/p\u003e\n"]]],["ML Kit's barcode scanning API reads data from most standard barcode formats on the device without needing a network connection. It automatically detects and parses structured data from 2D formats like QR codes, recognizing information such as URLs, contact details, and WiFi credentials. The API supports various linear and 2D formats, works with any barcode orientation, and offers a Google code scanner option for a faster, safer, permission-less experience. It does not recognize some formats including some 1D and ITF barcodes.\n"],null,["With ML Kit's barcode scanning API, you can read data encoded using most\nstandard barcode formats. Barcode scanning happens on the device, and doesn't\nrequire a network connection.\n\nBarcodes are a convenient way to pass information from the real world to your\napp. In particular, when using 2D formats such as QR code, you can encode\nstructured data such as contact information or WiFi network credentials. Because\nML Kit can automatically recognize and parse this data, your app can respond\nintelligently when a user scans a barcode.\n\nFor users who don't require custom UI, we recommend using the\n[Google code scanner](/ml-kit/vision/barcode-scanning/code-scanner). The code\nscanner API uses the same inference model as the standard Barcode scanning API,\nbut returns only the most centralized barcode for a faster and more consistent\nexperience. Google code scanner is also safer and permission-less, and does not\nrequire camera-related implementation or permissions.\n\n[iOS](/ml-kit/vision/barcode-scanning/ios)\n[Android](/ml-kit/vision/barcode-scanning/android)\n[Google code scanner](/ml-kit/vision/barcode-scanning/code-scanner)\n\nKey capabilities\n\nReads most standard formats\n:\n - Linear formats: Codabar, Code 39, Code 93, Code 128, EAN-8, EAN-13, ITF, UPC-A, UPC-E\n - 2D formats: Aztec, Data Matrix, PDF417, QR Code\n\nAutomatic format detection\n: Scan for all supported barcode formats at once without having to specify\n the format you're looking for, or boost scanning speed by restricting the\n detector to only the formats you're interested in.\n\nExtracts structured data\n: Structured data that's stored using one of the supported 2D formats is\n automatically parsed. Supported information types include URLs,\n contact information, calendar events, email addresses, phone\n numbers, SMS message prompts, ISBNs, WiFi connection information,\n geographic location, and AAMVA-standard driver information.\n\nWorks with any orientation\n: Barcodes are recognized and scanned regardless of their orientation:\n right-side-up, upside-down, or sideways.\n\nRuns on the device\n: Barcode scanning is performed completely on the device, and doesn't\n require a network connection.\n\nNote that this API does not recognize barcodes in these forms:\n\n- 1D Barcodes with only one character\n- Barcodes in ITF format with fewer than six characters, and this format is known to be flaky due to absence of checksum\n- Barcodes encoded with FNC2, FNC3 or FNC4\n- QR codes generated in the ECI mode\n\nThis API recognizes no more than 10 barcodes per API call.\n\nExample results\n\n|---|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | | Result || |---------------|------------------------------------------| | **Corners** | (49,125), (172,125), (172,160), (49,160) | | **Raw value** | 2404105001722 | |\n\n|---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | | Result || |----------------------|-----------------------------------------------------------------------------------------------------------------| | **Corners** | (87,87) (612,87) (612,612) (87,612) | | **Raw value** | `WIFI:S:SB1Guest;P:12345;T:WEP;;` | | **WiFi information** | |--------------|----------| | **SSID** | SB1Guest | | **Password** | 12345 | | **Type** | WEP | | |"]]