douglasjunior / react-native-easybluetooth-classic

⚛ A Library for easy implementation of Serial Bluetooth Classic on React Native (Android Only).
https://www.npmjs.com/package/easy-bluetooth-classic
MIT License
43 stars 7 forks source link

Example #16

Closed dedisetiaji closed 6 years ago

dedisetiaji commented 6 years ago

Hi, Would you like give some example to display discovery bluetooth device. I used devices.foreach and then put it in new state. But i failed to display the list

douglasjunior commented 6 years ago

You dont need to forEach, just put devices array to state and show it with a FlatList.

aidooyaw1992 commented 6 years ago

PLEASE I REALLY BEG YOU, give us a sample code ok

aidooyaw1992 commented 6 years ago

im trying to use the connect device but its not working

aidooyaw1992 commented 6 years ago
connect(device){
        console.log(device);
        EasyBluetooth.connect(device)
      .then(() => {
        console.log("Connected!");
      })
      .catch((ex) => {
        console.warn(ex);
      })
    } 
onDeviceFound(device) {
    console.log("onDeviceFound");
    console.log(device);
    var peripherals = this.state.peripherals;
        if (!peripherals.has(device.address)){
          console.warn('Got  peripheral', device);
          peripherals.set(device.address, device);
          this.setState({ peripherals });
        }

  }
<ListView
                    enableEmptySections={true}
                    dataSource={dataSource}
                    renderRow={(item) => {
                    const color = item.connected ? 'green' : '#fff';
                    return (
                        <TouchableHighlight onPress={() => this.connect(item) }>
                        <View style={[styles.row, {backgroundColor: color}]}>
                            <Text style={{fontSize: 12, textAlign: 'center', color: '#333333', padding: 10}}>{item.name}</Text>
                            <Text style={{fontSize: 8, textAlign: 'center', color: '#333333', padding: 10}}>{item.address}</Text>
                        </View>
                        </TouchableHighlight>
                    );
                    }}
                    />   
douglasjunior commented 6 years ago

All you need to know is in the Readme: https://github.com/douglasjunior/react-native-easybluetooth-classic#use

If you need help, make a better explanation of your problems.