Quét mã vạch
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.

Thông qua API quét mã vạch của Bộ công cụ học máy, bạn có thể đọc dữ liệu được mã hoá bằng hầu hết các định dạng mã vạch chuẩn. Quá trình quét mã vạch diễn ra trên thiết bị và không yêu cầu kết nối mạng.
Mã vạch là một cách thuận tiện để truyền thông tin từ thế giới thực sang ứng dụng của bạn. Cụ thể, khi sử dụng các định dạng 2D như mã QR, bạn có thể mã hoá dữ liệu có cấu trúc như thông tin liên hệ hoặc thông tin xác thực mạng Wi-Fi. Vì Bộ công cụ học máy có thể tự động nhận dạng và phân tích cú pháp dữ liệu này, nên ứng dụng của bạn có thể phản hồi một cách thông minh khi người dùng quét mã vạch.
Đối với người dùng không yêu cầu giao diện người dùng tuỳ chỉnh, bạn nên sử dụng trình quét mã của Google. API trình quét mã sử dụng mô hình dự đoán giống như API quét mã vạch tiêu chuẩn, nhưng chỉ trả về mã vạch tập trung nhất để mang lại trải nghiệm nhanh hơn và nhất quán hơn. Trình quét mã của Google cũng an toàn hơn và không cần quyền, đồng thời không yêu cầu triển khai hoặc cấp quyền liên quan đến máy ảnh.
iOS
Android
Trình quét mã của Google
Các khả năng chính
- Đọc được hầu hết các định dạng tiêu chuẩn
- Định dạng tuyến tính: Codabar, Code 39, Code 93, Code 128, EAN-8, EAN-13, ITF, UPC-A, UPC-E
- Định dạng 2D: Aztec, Ma trận dữ liệu, PDF417, Mã QR
- Tự động phát hiện định dạng
- Quét đồng thời mọi định dạng mã vạch được hỗ trợ mà không cần chỉ định định dạng bạn cần, hoặc tăng tốc độ quét bằng cách giới hạn trình phát hiện ở những định dạng mà bạn quan tâm.
- Trích xuất dữ liệu có cấu trúc
- Dữ liệu có cấu trúc được lưu trữ bằng một trong các định dạng 2D được hỗ trợ sẽ được tự động phân tích cú pháp. Các loại thông tin được hỗ trợ bao gồm URL, thông tin liên hệ, sự kiện trên lịch, địa chỉ email, số điện thoại, lời nhắc tin nhắn SMS, ISBN, thông tin kết nối Wi-Fi, vị trí địa lý và thông tin người lái xe theo tiêu chuẩn AAMVA.
- Hoạt động với mọi hướng
- Mã vạch được nhận dạng và quét bất kể hướng của mã:
phải, lộn ngược hay sang một bên.
- Chạy trên thiết bị
- Quá trình quét mã vạch được thực hiện hoàn toàn trên thiết bị và không cần kết nối mạng.
Xin lưu ý rằng API này không nhận dạng được mã vạch ở những dạng sau:
- Mã vạch 1D chỉ có một ký tự
- Mã vạch ở định dạng ITF có ít hơn 6 ký tự và định dạng này được coi là không ổn định do không có giá trị tổng kiểm
- Mã vạch được mã hoá bằng FNC2, FNC3 hoặc FNC4
- Mã QR được tạo ở chế độ ECI
API này nhận dạng không quá 10 mã vạch cho mỗi lệnh gọi API.
Kết quả mẫu
|
Kết quả |
Góc |
(49.125), (172.125), (172.160), (49.160) |
Giá trị thô |
2404105001722 |
|
|
Kết quả |
Góc |
(87.87) (612.87) (612.612) (87.612) |
Giá trị thô |
WIFI:S:SB1Guest;P:12345;T:WEP;; |
Thông tin về Wi-Fi |
SSID |
SB1Guest |
Mật khẩu |
12345 |
Loại |
WEP |
|
|
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-29 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-29 UTC."],[[["\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 | | |"]]