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

Activity triggering using react-native-bluetooth-serial #99

Open
mabn123 opened this issue Feb 3, 2019 · 4 comments
Open

Activity triggering using react-native-bluetooth-serial #99

mabn123 opened this issue Feb 3, 2019 · 4 comments

Comments

@mabn123
Copy link

mabn123 commented Feb 3, 2019

Is it possible to trigger a navigation to a different activity/screen after detecting a specified bluetooth id? and how? I have been trying to make it happen but weren't successful

@ivankfit
Copy link

this should give you a hint
connect (device) {
this.setState({ connecting: true })
BluetoothSerial.connect(device.id)
.then((res) => {
console.log(Connected to device ${device.name})
this.setState({ device, connected: true, connecting: false })
//////add this line to the connect function
this.props.navigation.navigate('Second',{device:device});
})
.catch((err) => console.log(err.message))
}

@mabn123
Copy link
Author

mabn123 commented Mar 28, 2019

Thank you very much for the hint, however, my case requires me to utilize the BluetoothSerial.discoverUnpairedDevices() to scan for available unpaired devices and when a determined bluetooth id say AA:BB:CC:DD:EE:FF is scanned, the function would automatically trigger a different activity/screen

@mabn123
Copy link
Author

mabn123 commented Mar 28, 2019

This is what I have come out so far but the activity never triggered despite the fact that the bluetooth signal exist:
`
discoverUnpaired () {

const { unpairedDevices } = this.state ;

if (this.state.discovering) {
  return false
} 

else {
  this.setState({ discovering: true })
  BluetoothSerial.discoverUnpairedDevices()
  .then((unpairedDevices) => {
    this.setState({ unpairedDevices, discovering: false })
  })
  .catch((err) => Toast.showShortBottom(err.message))

    unpairedDevices.filter(function(device){
      return device.id == this.state.DEVICE_ID;
    }).map(function(device,i){
        if (device.id === this.state.DEVICE_ID){
          this.props.navigation.navigate('Second');
        }
    });

}

}

`

@mabn123
Copy link
Author

mabn123 commented Mar 28, 2019

The 'this.state.DEVICE_ID' is where the target device's device id is kept

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

2 participants