react-native-bluetooth-headset-detect-ex

0.0.2 • Public • Published

react-native-bluetooth-headset-detect

Bluetooth Headset Detection for React Native

Getting started

$ npm install react-native-bluetooth-headset-detect --save

If you use react-native < 0.60

$ react-native link react-native-bluetooth-headset-detect

Usage

With React hooks:

import { useBluetoothHeadsetDetection } from 'react-native-bluetooth-headset-detect';
 
const MyComponent = () => {
  const device = useBluetoothHeadsetDetection();
  return (
    <Text>Connected headset: {device}</Text>
  );
};

Without React hooks:

import {
  getHeadset,
  addListener,
  removeListener,
} from 'react-native-bluetooth-headset-detect';
 
console.log('Connected device:', getHeadset());
addListener((device) => {
  console.log('Connected device:', device);
});

Legacy (not recommended):

import { NativeEventEmitter, NativeModules } from "react-native";
 
const BluetoothHeadsetDetectModule = NativeModules.RNBluetoothHeadsetDetect;
const bluetoothHeadsetDetectEmitter = new NativeEventEmitter(
  BluetoothHeadsetDetectModule
);
bluetoothHeadsetDetectEmitter.addListener("onChange", ({ devices }) => {
  if (devices.length) {
    console.log("Connected device:", devices[0]);
  } else {
    console.log("No devices connected");
  }
});

Demo project

https://github.com/alexkorep/react-native-bluetooth-headset-detect-demo

Readme

Keywords

Package Sidebar

Install

npm i react-native-bluetooth-headset-detect-ex

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

27.1 kB

Total Files

18

Last publish

Collaborators

  • wzc5840