संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Google कोड स्कैनर एपीआई, कोड स्कैन करने का पूरा समाधान उपलब्ध कराता है. इसके लिए, आपके ऐप्लिकेशन को कैमरे की अनुमति का अनुरोध करने की ज़रूरत नहीं होती. साथ ही, यह उपयोगकर्ता की निजता को बनाए रखता है. ऐसा करने के लिए, कोड को स्कैन करने का काम Google Play services को सौंपा जाता है. साथ ही, आपके ऐप्लिकेशन को सिर्फ़ स्कैन के नतीजे दिखाए जाते हैं (वीडियो 1).
इमेज की प्रोसेसिंग पूरी तरह से डिवाइस पर होती है. Google, नतीजों या इमेज के डेटा को सेव नहीं करता. यह एपीआई, ML Kit Barcode Scanning API के जैसे ही कोड फ़ॉर्मैट के साथ काम करता है और वही Barcode ऑब्जेक्ट दिखाता है.
यह एपीआई उन ऐप्लिकेशन के लिए सबसे सही है जिन्हें कस्टम यूज़र इंटरफ़ेस (यूआई) या कैमरे के अनुभव के बिना, आसानी से कोड स्कैन करने की ज़रूरत होती है. यह सुविधा पूरी तरह से Google Play services में काम करती है. इससे आपके ऐप्लिकेशन के साइज़ पर कम से कम असर पड़ता है.
16.1.0 वर्शन से, ऑटो-ज़ूम की सुविधा चालू की जा सकती है. इससे Google कोड स्कैनर, कैमरे से दूर मौजूद बारकोड को अपने-आप स्कैन कर पाएगा. जब उपयोगकर्ता अपने डिवाइसों को किसी बारकोड पर ले जाते हैं, तो स्कैनर अपने-आप बारकोड का पता लगा लेता है और उस पर ज़ूम इन कर देता है. इससे, ज़ूम में मैन्युअल बदलाव करने की ज़रूरत नहीं पड़ती. साथ ही, बारकोड को तेज़ी से, ज़्यादा सटीक, और आसानी से स्कैन किया जा सकता है (दूसरा वीडियो देखें).
पहला वीडियो. Google कोड स्कैनर इंटिग्रेशन
दूसरा वीडियो. अपने-आप ज़ूम होने की सुविधा
इस्तेमाल के ऐसे ज़्यादा जटिल उदाहरणों के लिए जिनमें कस्टम यूज़र इंटरफ़ेस (यूआई) की ज़रूरत होती है, हमारा सुझाव है कि आप सीधे ML Kit Barcode Scanning API का इस्तेमाल करें.
अगर आपका कोई सवाल है, आपको कोई गड़बड़ी सबमिट करनी है या आपको मदद चाहिए, तो ML Kit के कम्यूनिटी पेज पर जाएं.
शुरू करने से पहले
अपने ऐप्लिकेशन को तैयार करने के लिए, नीचे दिए गए सेक्शन में दिया गया तरीका अपनाएं.
अपने मॉड्यूल की Gradle बिल्ड फ़ाइल में, play-services-code-scanner
SDK टूल के लिए Google Play services की डिपेंडेंसी जोड़ें. आम तौर पर, यह फ़ाइल app/build.gradle होती है:
अपने ऐप्लिकेशन को इस तरह कॉन्फ़िगर किया जा सकता है कि Google Play services, Play Store से आपका ऐप्लिकेशन इंस्टॉल होने के दौरान, डिवाइस पर स्कैनर मॉड्यूल को अपने-आप डाउनलोड कर ले.
स्कैनर मॉड्यूल की उपलब्धता की साफ़ तौर पर जांच की जा सकती है. साथ ही, Google Play services के ModuleInstallClient API की मदद से, डाउनलोड का अनुरोध भी किया जा सकता है.
अगर आपने इंस्टॉल के समय मॉड्यूल डाउनलोड करने की सुविधा चालू नहीं की है या साफ़ तौर पर डाउनलोड करने का अनुरोध नहीं किया है और स्कैनर मॉड्यूल, किसी दूसरे इस्तेमाल के उदाहरण के लिए पहले से इंस्टॉल नहीं है, तो Google Play services, स्कैनर मॉड्यूल का इस्तेमाल होने पर पहली बार उसे डाउनलोड करता है.
कोड स्कैन करना
बारकोड स्कैन करने के लिए, यह तरीका अपनाएं.
ज़रूरी नहीं: कोड स्कैनर को कॉन्फ़िगर करें.
अगर आपको पता है कि आपको कौनसे बारकोड फ़ॉर्मैट पढ़ने हैं, तो सिर्फ़ उन फ़ॉर्मैट का पता लगाने के लिए बारकोड डिटेक्टर को कॉन्फ़िगर करके, उसकी स्पीड को बेहतर बनाया जा सकता है. उदाहरण के लिए, सिर्फ़ Aztec कोड और क्यूआर कोड का पता लगाने के लिए, यहां दिए गए उदाहरण की तरह एक GmsBarcodeScannerOptions ऑब्जेक्ट बनाएं:
अपने-आप ज़ूम होने की सुविधा, डिफ़ॉल्ट रूप से बंद रहती है. 16.1.0 वर्शन से, अपने-आप ज़ूम होने की सुविधा चालू करने के लिए, नीचे दिए गए कोड उदाहरण में दिखाए गए तरीके से enableAutoZoom() को कॉल करें.
Kotlin
valoptions=GmsBarcodeScannerOptions.Builder().setBarcodeFormats(...).enableAutoZoom()// available on 16.1.0 and higher.build()
Java
GmsBarcodeScannerOptionsoptions=newGmsBarcodeScannerOptions.Builder().setBarcodeFormats(...).enableAutoZoom()// available on 16.1.0 and higher.build();
कोड के उदाहरण में दिखाए गए तरीके से, GmsBarcodeScanner का एक इंस्टेंस पाएं:
Kotlin
valscanner=GmsBarcodeScanning.getClient(this)// Or with a configured options// val scanner = GmsBarcodeScanning.getClient(this, options)
Java
GmsBarcodeScannerscanner=GmsBarcodeScanning.getClient(this);// Or with a configured options// GmsBarcodeScanner scanner = GmsBarcodeScanning.getClient(context, options);
startScan() पर कॉल करके, कोड स्कैन करने का अनुरोध करें.
Kotlin
scanner.startScan().addOnSuccessListener{barcode->// Task completed successfully}.addOnCanceledListener{// Task canceled}.addOnFailureListener{e->// Task failed with an exception}
Java
scanner.startScan().addOnSuccessListener(barcode->{// Task completed successfully}).addOnCanceledListener(()->{// Task canceled}).addOnFailureListener(e->{// Task failed with an exception});
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-08-17 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eThe Google Code Scanner API enables code scanning without requiring camera permission, preserving user privacy by delegating the task to Google Play services.\u003c/p\u003e\n"],["\u003cp\u003eIt supports various code formats, returns a \u003ccode\u003eBarcode\u003c/code\u003e object, and is ideal for apps needing seamless code scanning without a custom UI.\u003c/p\u003e\n"],["\u003cp\u003eAuto-zoom, available from version 16.1.0, automatically zooms in on barcodes, eliminating the need for manual adjustments and making scanning faster and more accurate.\u003c/p\u003e\n"],["\u003cp\u003eThe API uses an unbundled library downloaded before use and requires Android API level 21 or higher.\u003c/p\u003e\n"],["\u003cp\u003eFor complex use cases requiring a custom UI, the ML Kit Barcode Scanning API is recommended.\u003c/p\u003e\n"]]],[],null,["The Google code scanner API provides a complete solution for scanning code\nwithout requiring your app to request camera permission, while preserving user\nprivacy. This is accomplished by delegating the task of scanning the code to\nGoogle Play services and returning only the scan results to your app (Video 1).\nAll image processing occurs on the device and Google doesn't store the results\nor image data. The API supports the same code formats as the\n[ML Kit Barcode Scanning API](/ml-kit/vision/barcode-scanning) and returns the\nsame [`Barcode`](/android/reference/com/google/mlkit/vision/barcode/common/Barcode)\nobject.\n\nThis API is ideal for apps that require seamless code scanning without the need\nfor a custom UI or camera experience. The implementation resides entirely within\nGoogle Play services, ensuring minimal impact on the size of your app.\n\nStarting with version 16.1.0, you can enable auto-zoom to allow the Google code\nscanner to automatically scan barcodes that are far away from the camera. When\nusers point their devices at a barcode, the scanner will intelligently detect\nand zoom in on the barcode. This eliminates the need for manual zoom\nadjustments, making barcode scanning faster, more accurate and more accessible\n(see Video 2).\n\n|------------------------------------------|---------------------------|\n| | |\n| Video 1. Google code scanner integration | Video 2. Auto-zoom effect |\n\n\u003cbr /\u003e\n\nFor more complex use cases that require a custom UI, we recommend using the\n[ML Kit Barcode Scanning API](/ml-kit/vision/barcode-scanning) directly.\n\nIf you have questions, want to submit a bug, or need assistance, check the\n[ML Kit community page](/ml-kit/community).\n| This API uses an unbundled library that must be downloaded before use. See [this guide](/ml-kit/tips/installation-paths) for more information.\n\nBefore you begin This API requires Android API level 21 or above. Make sure that your app's build file uses a `minSdkVersion` value of 21 or higher.\n\nTo prepare your app, complete the steps in the following sections.\n\nConfigure your app\n\n1. In your top-level `settings.gradle` file, include\n [Google's Maven repository](https://maven.google.com/web/index.html) and\n [Maven central repository](https://search.maven.org/artifact) in under the\n `dependencyResolutionManagement` block:\n\n dependencyResolutionManagement {\n repositories {\n google()\n mavenCentral()\n }\n }\n\n2. Add the Google Play services dependency for the `play-services-code-scanner`\n SDK to your module's Gradle build file, which is commonly `app/build.gradle`:\n\n dependencies {\n implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'\n }\n\n3. You can configure your app to have Google Play services automatically\n download the scanner module to the device while your app is installed from\n the Play Store.\n\n \u003capplication ...\u003e\n ...\n \u003cmeta-data\n android:name=\"com.google.mlkit.vision.DEPENDENCIES\"\n android:value=\"barcode_ui\"/\u003e\n ...\n \u003c/application\u003e\n\n You can also explicitly check the scanner module availability and request\n download through Google Play services [ModuleInstallClient\n API](https://developers.google.com/android/guides/module-install-apis).\n\n If you don't enable install-time module downloads or request explicit\n downloads---and the scanner module isn't already installed for another\n use case---Google Play services downloads the scanner module the first\n time it's used.\n\nScan a code\n\nImplement the following steps to scan a barcode.\n\n1. Optional: Configure the code scanner.\n\n If you know which barcode formats you expect to read, you can improve the\n speed of the barcode detector by configuring it to only detect those\n formats. For example, to detect only Aztec code and QR codes, build a\n [`GmsBarcodeScannerOptions`](/android/reference/com/google/mlkit/vision/codescanner/GmsBarcodeScannerOptions.Builder)\n object as in the following example: \n\n Kotlin \n\n ```kotlin\n val options = GmsBarcodeScannerOptions.Builder()\n .setBarcodeFormats(\n Barcode.FORMAT_QR_CODE,\n Barcode.FORMAT_AZTEC)\n .build()\n ```\n\n Java \n\n ```java\n GmsBarcodeScannerOptions options = new GmsBarcodeScannerOptions.Builder()\n .setBarcodeFormats(\n Barcode.FORMAT_QR_CODE,\n Barcode.FORMAT_AZTEC)\n .build();\n ```\n\n By default, auto-zoom is turned off. To enable auto-zoom functionality\n starting in version 16.1.0, call `enableAutoZoom()` as shown in the\n following code example. \n\n Kotlin \n\n ```kotlin\n val options = GmsBarcodeScannerOptions.Builder()\n .setBarcodeFormats(...)\n .enableAutoZoom() // available on 16.1.0 and higher\n .build()\n ```\n\n Java \n\n ```java\n GmsBarcodeScannerOptions options = new GmsBarcodeScannerOptions.Builder()\n .setBarcodeFormats(...)\n .enableAutoZoom() // available on 16.1.0 and higher\n .build();\n ```\n2. Get an instance of [`GmsBarcodeScanner`](/android/reference/com/google/mlkit/vision/codescanner/GmsBarcodeScanner),\n as shown in the code example:\n\n Kotlin \n\n ```kotlin\n val scanner = GmsBarcodeScanning.getClient(this)\n // Or with a configured options\n // val scanner = GmsBarcodeScanning.getClient(this, options)\n ```\n\n Java \n\n ```java\n GmsBarcodeScanner scanner = GmsBarcodeScanning.getClient(this);\n // Or with a configured options\n // GmsBarcodeScanner scanner = GmsBarcodeScanning.getClient(context, options);\n ```\n3. Request a code scanning by calling [`startScan()`](/android/reference/com/google/mlkit/vision/codescanner/GmsBarcodeScanner#startScan()).\n\n Kotlin \n\n ```kotlin\n scanner.startScan()\n .addOnSuccessListener { barcode -\u003e\n // Task completed successfully\n }\n .addOnCanceledListener {\n // Task canceled\n }\n .addOnFailureListener { e -\u003e\n // Task failed with an exception\n }\n ```\n\n Java \n\n ```java\n scanner\n .startScan()\n .addOnSuccessListener(\n barcode -\u003e {\n // Task completed successfully\n })\n .addOnCanceledListener(\n () -\u003e {\n // Task canceled\n })\n .addOnFailureListener(\n e -\u003e {\n // Task failed with an exception\n });\n ```\n4. Handle the resulting [`Barcode`](/android/reference/com/google/mlkit/vision/barcode/common/Barcode).\n\n Kotlin \n\n ```kotlin\n val rawValue: String? = barcode.rawValue\n ```\n\n Java \n\n ```java\n String rawValue = barcode.getRawValue();\n ```"]]