alexkendall / react-native-bluetooth-cross-platform

Cross-Platform Bluetooth & WiFi React Native Module. Powered by underdark http://underdark.io/.
179 stars 35 forks source link

android discovery not working #46

Open ashmortar opened 6 years ago

ashmortar commented 6 years ago

I have set up a project in react-native and am trying to locate peers and advertise via bluetooth but when i getNearbyPeers the array returned is always empty. Are there any examples of how this is supposed to work?

HZSamir commented 6 years ago

This is how I personally go about it:

BluetoothCP.advertise();
    // BluetoothCP.browse();

    BluetoothCP.addPeerDetectedListener(function(user) {
      if (typeof user !== 'undefined' && user !== null) {
        BluetoothCP.inviteUser(user.id);
        self.props.dispatch(SessionStateActions.addUser());
      }
    });

    BluetoothCP.addPeerLostListener(function(user) {
      self.setState({usersNumber: self.state.usersNumber - 1});
      if (typeof user !== 'undefined' && user !== null) {
        BluetoothCP.disconnectFromPeer(user.id);
        self.props.dispatch(SessionStateActions.removeUser());
      }
    });

    BluetoothCP.addInviteListener(function(user) {
      if (typeof user !== 'undefined' && user !== null) {
        BluetoothCP.acceptInvitation(user.id);
      }
    });

I have to check the user object because sometimes it would return an undefined The action dispatched just logs the new discovered user somewhere in my app.

vimalathiyagu commented 6 years ago

@virl I am also facing the same issue. I am using android 8 and only when wifi is turned on (But no internet) along bluetooth only then discovery works. It is not working only with bluetooth alone. Previously only bluetooth was working fine on android versions below 8.

Is there any specific handling to be done for devices above Android 7. Kindly clarify.

virl commented 6 years ago

@vimalathiyagu Currently Bluetooth discovery and communication are not supported when both devices are Android 8+.

vimalathiyagu commented 6 years ago

Thanks @virl

tonmanayo commented 5 years ago

@virl will bluetooth be working again anytime soon?

MaksymilianWojcik commented 5 years ago

hey @virl is there any update on 8+ versions issue?