Getting Started
このコンテンツはまだあなたの言語で利用できません。
Install
Section titled “Install”bun add @capgo/capacitor-bluetooth-low-energybunx cap syncImport
Section titled “Import”import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';API Overview
Section titled “API Overview”initialize
Section titled “initialize”Initialize the BLE plugin. Must be called before any other method.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.initialize({ mode: 'central' });shimWebBluetooth
Section titled “shimWebBluetooth”Install the Capacitor Web Bluetooth shim on navigator.bluetooth.
Call this manually before using the Web Bluetooth API from a Capacitor native app.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
BluetoothLowEnergy.shimWebBluetooth();isAvailable
Section titled “isAvailable”Check if Bluetooth is available on the device.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { available } = await BluetoothLowEnergy.isAvailable();isEnabled
Section titled “isEnabled”Check if Bluetooth is enabled on the device.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isEnabled();isLocationEnabled
Section titled “isLocationEnabled”Check if location services are enabled (Android only).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isLocationEnabled();openAppSettings
Section titled “openAppSettings”Open the app settings page.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openAppSettings();openBluetoothSettings
Section titled “openBluetoothSettings”Open the Bluetooth settings page (Android only).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openBluetoothSettings();openLocationSettings
Section titled “openLocationSettings”Open the location settings page (Android only).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openLocationSettings();checkPermissions
Section titled “checkPermissions”Check the current permission status.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bluetooth, location } = await BluetoothLowEnergy.checkPermissions();requestPermissions
Section titled “requestPermissions”Request Bluetooth permissions.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bluetooth, location } = await BluetoothLowEnergy.requestPermissions();startScan
Section titled “startScan”Start scanning for BLE devices.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startScan({ services: ['180D'], // Heart Rate Service timeout: 10000});stopScan
Section titled “stopScan”Stop scanning for BLE devices.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopScan();connect
Section titled “connect”Connect to a BLE device.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.connect({ deviceId: 'AA:BB:CC:DD:EE:FF' });disconnect
Section titled “disconnect”Disconnect from a BLE device.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.disconnect({ deviceId: 'AA:BB:CC:DD:EE:FF' });createBond
Section titled “createBond”Create a bond with a BLE device (Android only).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.createBond({ deviceId: 'AA:BB:CC:DD:EE:FF' });isBonded
Section titled “isBonded”Check if a device is bonded (Android only).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bonded } = await BluetoothLowEnergy.isBonded({ deviceId: 'AA:BB:CC:DD:EE:FF' });discoverServices
Section titled “discoverServices”Discover services on a connected device.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.discoverServices({ deviceId: 'AA:BB:CC:DD:EE:FF' });getServices
Section titled “getServices”Get discovered services for a device.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { services } = await BluetoothLowEnergy.getServices({ deviceId: 'AA:BB:CC:DD:EE:FF' });getConnectedDevices
Section titled “getConnectedDevices”Get a list of connected devices.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { devices } = await BluetoothLowEnergy.getConnectedDevices();readCharacteristic
Section titled “readCharacteristic”Read a characteristic value.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { value } = await BluetoothLowEnergy.readCharacteristic({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37'});writeCharacteristic
Section titled “writeCharacteristic”Write a value to a characteristic.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.writeCharacteristic({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A39', value: [0x01]});startCharacteristicNotifications
Section titled “startCharacteristicNotifications”Start notifications for a characteristic.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startCharacteristicNotifications({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37'});stopCharacteristicNotifications
Section titled “stopCharacteristicNotifications”Stop notifications for a characteristic.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopCharacteristicNotifications({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37'});readDescriptor
Section titled “readDescriptor”Read a descriptor value.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { value } = await BluetoothLowEnergy.readDescriptor({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37', descriptor: '2902'});writeDescriptor
Section titled “writeDescriptor”Write a value to a descriptor.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.writeDescriptor({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37', descriptor: '2902', value: [0x01, 0x00]});readRssi
Section titled “readRssi”Read the RSSI (signal strength) of a connected device.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { rssi } = await BluetoothLowEnergy.readRssi({ deviceId: 'AA:BB:CC:DD:EE:FF' });requestMtu
Section titled “requestMtu”Request MTU size change (Android only).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { mtu } = await BluetoothLowEnergy.requestMtu({ deviceId: 'AA:BB:CC:DD:EE:FF', mtu: 512});requestConnectionPriority
Section titled “requestConnectionPriority”Request connection priority (Android only).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.requestConnectionPriority({ deviceId: 'AA:BB:CC:DD:EE:FF', priority: 'high'});startAdvertising
Section titled “startAdvertising”Start advertising as a peripheral (BLE server).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startAdvertising({ name: 'MyDevice', services: ['180D']});stopAdvertising
Section titled “stopAdvertising”Stop advertising.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopAdvertising();startForegroundService
Section titled “startForegroundService”Start a foreground service to maintain BLE connections in background (Android only).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startForegroundService({ title: 'BLE Connection', body: 'Maintaining connection...'});stopForegroundService
Section titled “stopForegroundService”Stop the foreground service (Android only).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopForegroundService();Type Reference
Section titled “Type Reference”InitializeOptions
Section titled “InitializeOptions”Initialization options for the plugin.
export interface InitializeOptions { /** * The mode to initialize the plugin in. * - 'central': Act as a BLE central (client) * - 'peripheral': Act as a BLE peripheral (server) * * @default 'central' * @since 1.0.0 */ mode?: 'central' | 'peripheral';}IsAvailableResult
Section titled “IsAvailableResult”Result of the isAvailable method.
export interface IsAvailableResult { /** * Whether Bluetooth is available on the device. * * @since 1.0.0 */ available: boolean;}IsEnabledResult
Section titled “IsEnabledResult”Result of the isEnabled method.
export interface IsEnabledResult { /** * Whether Bluetooth is enabled on the device. * * @since 1.0.0 */ enabled: boolean;}IsLocationEnabledResult
Section titled “IsLocationEnabledResult”Result of the isLocationEnabled method.
export interface IsLocationEnabledResult { /** * Whether location services are enabled on the device. * * @since 1.0.0 */ enabled: boolean;}PermissionStatus
Section titled “PermissionStatus”Permission status for Bluetooth and location.
export interface PermissionStatus { /** * Bluetooth permission status. * * @since 1.0.0 */ bluetooth: PermissionState;
/** * Location permission status (Android only). * * @since 1.0.0 */ location: PermissionState;}StartScanOptions
Section titled “StartScanOptions”Options for starting a scan.
export interface StartScanOptions { /** * List of service UUIDs to filter by. * Only devices advertising these services will be returned. * * @since 1.0.0 */ services?: string[];
/** * Scan timeout in milliseconds. * Set to 0 for no timeout. * * @default 0 * @since 1.0.0 */ timeout?: number;
/** * Whether to allow duplicate scan results. * * @default false * @since 1.0.0 */ allowDuplicates?: boolean;}ConnectOptions
Section titled “ConnectOptions”Options for connecting to a device.
export interface ConnectOptions { /** * The device ID (MAC address on Android, UUID on iOS). * * @since 1.0.0 */ deviceId: string;
/** * Whether to automatically connect when the device becomes available. * * @default false * @since 1.0.0 */ autoConnect?: boolean;}DisconnectOptions
Section titled “DisconnectOptions”Options for disconnecting from a device.
export interface DisconnectOptions { /** * The device ID to disconnect from. * * @since 1.0.0 */ deviceId: string;}CreateBondOptions
Section titled “CreateBondOptions”Options for creating a bond.
export interface CreateBondOptions { /** * The device ID to bond with. * * @since 1.0.0 */ deviceId: string;}IsBondedOptions
Section titled “IsBondedOptions”Options for checking bond status.
export interface IsBondedOptions { /** * The device ID to check. * * @since 1.0.0 */ deviceId: string;}IsBondedResult
Section titled “IsBondedResult”Result of the isBonded method.
export interface IsBondedResult { /** * Whether the device is bonded. * * @since 1.0.0 */ bonded: boolean;}DiscoverServicesOptions
Section titled “DiscoverServicesOptions”Options for discovering services.
export interface DiscoverServicesOptions { /** * The device ID to discover services on. * * @since 1.0.0 */ deviceId: string;}Source Of Truth
Section titled “Source Of Truth”This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.