react-native-incall-manager icon indicating copy to clipboard operation
react-native-incall-manager copied to clipboard

How to check if Bluetooth Headset is connected

Open amirito opened this issue 2 years ago • 4 comments

I want to do sth when headset plugged in We have getIsWiredHeadsetPluggedIn() here for wired headset But what about bluetooth headset?

amirito avatar Nov 24 '21 12:11 amirito

I have the same problem, does anyone know how to solve it? Thanks

basilbai avatar Jan 07 '22 11:01 basilbai

Any news about this?

cruzlutor avatar Jan 16 '22 04:01 cruzlutor

@basilbai @cruzlutor @amirito were you able to solve it?

aryan-dwivedi avatar Feb 01 '22 14:02 aryan-dwivedi

@aryan-dwivedi Not with this library, I ended up using react-native-headphone-detection wrapping the logic in a hook like this

import { useState, useEffect } from 'react'
import HeadphoneDetection from 'react-native-headphone-detection'

export default function useHeadphone() {
  const [isHeadphoneConnected, setIsHeadphoneConnected] = useState<
    boolean | undefined
  >(false)

  useEffect(() => {
    HeadphoneDetection.addListener((result) => {
      setIsHeadphoneConnected(result.audioJack || result.bluetooth)
    })
    return () => {
      //@ts-ignore
      if (HeadphoneDetection.remove) HeadphoneDetection.remove()
    }
  }, [])

  return { isHeadphoneConnected }
}

It works for a wired headsets, but I haven't tried Bluetooth devices yet

cruzlutor avatar Feb 01 '22 14:02 cruzlutor