> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebellapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# my.openBluetoothAdapter

> Initialize the Bluetooth adapter.

Use this API to initialize the Bluetooth adapter. This must be called before using any other Bluetooth APIs.

## Parameters

| Property  | Type     | Required | Description                                                                                                 |
| --------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------- |
| autoClose | Boolean  | No       | Whether to automatically disconnect Bluetooth when leaving the current page. Default: `true`. Android only. |
| success   | Function | No       | Callback on success                                                                                         |
| fail      | Function | No       | Callback on failure                                                                                         |
| complete  | Function | No       | Callback that always executes                                                                               |

## Success Callback

| Property     | Type    | Description              |
| ------------ | ------- | ------------------------ |
| isSupportBLE | Boolean | Whether BLE is supported |

## Code Example

### Basic Usage

```javascript theme={null}
my.openBluetoothAdapter({
  success(res) {
    if (!res.isSupportBLE) {
      console.log('Bluetooth is unavailable temporarily');
      return;
    }
    console.log('Bluetooth adapter initialized');
  },
  fail(err) {
    console.error('Failed to initialize Bluetooth:', err);
  }
});
```

### Check Bluetooth Before Operations

```javascript theme={null}
Page({
  onLoad() {
    this.initBluetooth();
  },

  initBluetooth() {
    my.openBluetoothAdapter({
      success: () => {
        console.log('Bluetooth ready');
        this.setData({ bluetoothReady: true });
      },
      fail: (err) => {
        if (err.error === 10001) {
          my.alert({
            title: 'Bluetooth Required',
            content: 'Please enable Bluetooth to use this feature.'
          });
        }
      }
    });
  },

  onUnload() {
    my.closeBluetoothAdapter();
  }
});
```

## Error Codes

| Code | Description                                           | Solution                        |
| ---- | ----------------------------------------------------- | ------------------------------- |
| 12   | Bluetooth is not turned on.                           | Try again to turn on Bluetooth. |
| 13   | Connection to the system service is temporarily lost. | Try again to reconnect.         |
| 14   | Not authorized to use Bluetooth.                      | Authorize app to use Bluetooth. |
| 15   | Unknown error.                                        | -                               |

<Warning>
  Always call `my.closeBluetoothAdapter` when you're done using Bluetooth to release system resources.
</Warning>

## Related APIs

<CardGroup cols={2}>
  <Card title="my.closeBluetoothAdapter" icon="xmark" href="/jsapi/device/bluetooth/my.closeBluetoothAdapter">
    Close Bluetooth adapter
  </Card>

  <Card title="my.startBluetoothDevicesDiscovery" icon="magnifying-glass" href="/jsapi/device/bluetooth/my.startBluetoothDevicesDiscovery">
    Start device discovery
  </Card>
</CardGroup>
