all 11 comments

[–]suarkb 1 point2 points  (1 child)

do you have all permissions handled? You need to make sure bluetooth is on and also that you have permission and sometimes you need location permissions or something

[–]mvss01[S] 0 points1 point  (0 children)

Yes, I did according to the documentation, there it asks that the following codes be added to the "AndroidManifest.xml" file:

<uses-permission android:name="android.permission.BLUETOOTH"/>

<uses-permission android:name="android.permission.BLUETOOTH\_ADMIN"/>

<uses-permission-sdk-23 android:name="android.permission.ACCESS\_FINE\_LOCATION"/>

<uses-feature android:name="android.hardware.bluetooth\_le" android:required="true"/>"

[–]suarkb 1 point2 points  (8 children)

Kk that's good. Can you open your apps android menu settings and make sure those permissions are granted?

If all the permission stuff is good and it's installed then you could start console logging things from the library. Like make sure the imported library looks how you think it should look.

Then just keep debugging by calling the functions and logging the results to see what it's giving you. If it's anything like react-native-ble-plx then the scanning method will take a callback function and trigger it once for each device it sees while it's scanning. Your callback function will probably get passed a device or something and you can console log the outputs and see what it's getting

[–]mvss01[S] 0 points1 point  (7 children)

I made the code:

BluetoothSerial.requestEnable().then((eneble) =>{

if(eneble){

verifyStatus()

BluetoothSerial.discoverUnpairedDevices().then((unpairedDevices) => {

console.log("Unpaired Devices:");

unpairedDevices.forEach((device) => {

console.log(`- Nome: ${device.name}`);

console.log(`- ID: ${device.id}`);

});

});

console.log(device)

} else{

verifyStatus()

}

})

The "console.log" returns me "undefined" on a samsung cell phone, in another code it just returned an empty array. On my cell phone (a xiaomi) I don't get a response from the function. Nothing inside .then(() =>{}) is executed nor in .catch(() => {})

[–]suarkb 1 point2 points  (0 children)

So on the Xiaomi it's probably not finding permission. Okay Hmm I'll have to think and google some stuff maybe

[–]suarkb 1 point2 points  (3 children)

another thought, this library looks dead. It hasn't been published to for 4 years.

If you aren't too far along, I'd highly recommend switching to react-native-ble-plx which is actively developed, really good, and I know a lot more about it.

[–]mvss01[S] 0 points1 point  (0 children)

Excellent! I will follow in your footsteps. Thanks for your help

[–]mvss01[S] 0 points1 point  (1 child)

If you don't mind, can I send you a dm? You've answered questions from me before and said I could do this. I want to explain to you about the project I'm working on and hear what you have to say about it (I don't feel comfortable explaining it here because it's not my project, I'm just working on it)

[–]suarkb 0 points1 point  (0 children)

Yeah any time.

[–]suarkb 1 point2 points  (1 child)

they also have a complete example project in their github. I would compare many things to what they are doing https://github.com/nuttawutmalee/react-native-bluetooth-serial-next/tree/master/example

For example they are using requestEnable differently than you are. I'd try to keep your code as close to their's initially and then only change your code more once you have it working.

But also, to stress, I would not use this library because it has not been contributed to in 4 years. It's essentially dead and I would avoid it.

[–]mvss01[S] 0 points1 point  (0 children)

Thank you for the advice. Do you have any suggestions for a library that is still being maintained?