Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BluetoothStatus.state is always false #55

Open
gpawlik opened this issue Mar 19, 2020 · 7 comments
Open

BluetoothStatus.state is always false #55

gpawlik opened this issue Mar 19, 2020 · 7 comments

Comments

@gpawlik
Copy link

gpawlik commented Mar 19, 2020

No matter if the Bluetooth is switched on or off (both general settings and app settings) the state comes as false. Am I missing something?

import { BluetoothStatus } from 'react-native-bluetooth-status';
...
async checkBluetoothState() {
    const isEnabled = await BluetoothStatus.state();
    // false
}

When I inspect the state in the line https://github.com/solinor/react-native-bluetooth-status/blob/master/index.js#L28

this.subscription = bluetoothEvent.addListener(BT_STATUS_EVENT, state => {

state is undefined

@pzehle
Copy link

pzehle commented Aug 3, 2020

Library seems completely broken in my experience. iOS returns "Native module cannot be null", and Android returns always false, no matter what I do.

Did you find any workaround?

@zabojad
Copy link

zabojad commented Dec 14, 2020

It seems to happen on Samsung phones and tablets but not on a Google Pixel for example... Is this also what you observe?

@pktippa
Copy link

pktippa commented Mar 23, 2021

I started facing this issue after migrating from React Native 0.63.3 to 0.64.0

@schtomas
Copy link

schtomas commented May 25, 2021

I found a workeround for this. But its not a best solution for every app and case. But for my app as a temporary solution is acceptable.
I am using this library for Android. I need to see bluetooth status of device because i need to reconnect last connected thermal printer automaticly from AsyncStorage if it was once already connected. I have the following issue: in developing mode works this package just fine but in production i am dealing with same problem as above. The bluetooth status is always false even if its on. I found out when i turn off and on manualy bluetooth on device, btStatus is updated correctly. So i decided to turn off and on bluetooth in parent component in useEffect this will reset bluetooth on device and status correctly updated. Problem is, if you have connected some other device to phone it will be disconected. Second thing is it takes some time but you can use spinner if you want until btState is not true. I am using this (React Native 0.63.3) app for Android POS terminal so i am ok with that for now. But I hope this library will be fixed or i find other solution. I am adding my code as example

`
import { useBluetoothStatus } from 'react-native-bluetooth-status';
const [btStatus, isPending, setBluetooth] = useBluetoothStatus();

useEffect(() => {
loadAuthData();
loadLanguageSetting();

if (!btStatus) {
  setBluetooth(false);
  setBluetooth(true);
}

if (btStatus) {
  if (printers.length === 0) {
    BLEPrinter.init()
      .then(() => {
        searchBluetoothPrinters();
      })
  };

  if (printers.length > 0 && !currentPrinter) {
    setStoredPrinter();
  };
};

if (!btStatus && printers.length > 0) {
  disconnectPrinter();
  setPrinters([]);
}

}, [printers, btStatus, isPending]);
`

@dmontecillo
Copy link

Same issue but issue only found on Android im using below:

  1. react-native 0.64
  2. Android OS10

@naingmahar
Copy link

Same issue

@ycldz
Copy link

ycldz commented Nov 17, 2022

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants