メインコンテンツまでスキップ
バージョン: v8

@capacitor/barcode-scanner

Outsystems Barcodeライブラリを使用したCapacitorプラグイン

Install

npm install @capacitor/barcode-scanner
npx cap sync

Android

バーコードスキャナープラグインは、最小Android SDKターゲットが26である必要があります。これは、Capacitorアプリケーションに付属するデフォルトよりも高い値です。この値はandroid/variables.gradleファイルで更新できます。

ext {
minSdkVersion = 26
}

注意: ZXINGスキャンライブラリを使用するAndroidはすべてのフォーマットをサポートしますが、MLKITMAXICODERSS_14RSS_EXPANDEDUPC_EAN_EXTENSIONを除くすべてをサポートします - hintでこれらのいずれかを使用すると、デフォルトで任意のフォーマットをスキャンします。

iOS

バーコードスキャナーはデバイスのカメラを使用します。アプリケーションがデバイスのカメラにアクセスできるように、Info.plistファイルでPrivacy - Camera Usage Descriptionを設定してください。

注意: iOSはMAXICODEUPC_EAN_EXTENSIONを除くすべてのフォーマットをサポートします - hintでこれらを使用すると、デフォルトで任意のフォーマットをスキャンします。また、Apple VisionはUPC_AEAN_13を区別しないため、hintでこれらのいずれかを指定すると両方をスキャンできます。


API

Interface defining the contract for a plugin capable of scanning barcodes. Requires implementation of the scanBarcode method, which initiates a barcode scan with given options.

Starting in Android targetSdk 36, the scanOrientation parameter has no effect for large screens (e.g. tablets) on Android 16 and higher. You may opt-out of this behavior in your app by adding <property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY" android:value="true" /> to your AndroidManifest.xml inside <application> or <activity>. Keep in mind though that this opt-out is temporary and will no longer work for Android 17. Android discourages setting specific orientations for large screens. Regular Android phones are unaffected by this change. For more information check the Android docs at https://developer.android.com/about/versions/16/behavior-changes-16#adaptive-layouts

scanBarcode(...)

scanBarcode(options: CapacitorBarcodeScannerOptions) => Promise<CapacitorBarcodeScannerScanResult>
ParamType
options
CapacitorBarcodeScannerOptions

Returns:

Promise<CapacitorBarcodeScannerScanResult>


Type Aliases

CapacitorBarcodeScannerScanResult

Defines the structure of the result returned from a barcode scan.

{ ScanResult: string; format: CapacitorBarcodeScannerTypeHint; }

CapacitorBarcodeScannerTypeHint

Extends supported formats from Html5Qrcode with a special 'ALL' option, indicating support for all barcode types. Type definition combining Html5QrcodeSupportedFormats and OSBarcodeTypeHintALLOption to represent the hint for the type of barcode to be scanned.

Html5QrcodeSupportedFormats | CapacitorBarcodeScannerTypeHintALLOption

CapacitorBarcodeScannerOptions

Defines the options for configuring a barcode scan.

{ hint: CapacitorBarcodeScannerTypeHint; scanInstructions?: string; scanButton?: boolean; scanText?: string; cameraDirection?: CapacitorBarcodeScannerCameraDirection; scanOrientation?: CapacitorBarcodeScannerScanOrientation; android?: { scanningLibrary?: CapacitorBarcodeScannerAndroidScanningLibrary; }; web?: { showCameraSelection?: boolean; scannerFPS?: number; }; }

Enums

Html5QrcodeSupportedFormats

MembersValue
QR_CODE0
AZTEC1
CODABAR2
CODE_393
CODE_934
CODE_1285
DATA_MATRIX6
MAXICODE7
ITF8
EAN_139
EAN_810
PDF_41711
RSS_1412
RSS_EXPANDED13
UPC_A14
UPC_E15
UPC_EAN_EXTENSION16

CapacitorBarcodeScannerTypeHintALLOption

MembersValue
ALL17

CapacitorBarcodeScannerCameraDirection

MembersValue
BACK1
FRONT2

CapacitorBarcodeScannerScanOrientation

MembersValue
PORTRAIT1
LANDSCAPE2
ADAPTIVE3

CapacitorBarcodeScannerAndroidScanningLibrary

MembersValue
ZXING"zxing"
MLKIT"mlkit"