Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Unable to connect to Bluetooth device

$
0
0

I'm trying to connect to a Bluetooth device to receive barcode scan data (Using Visual Studio 2019, connected to an Android device running KitKat OS).

I've tried many tutorials and examples without any luck... Here's a few I used as a guidance :

When I do the following:
socket = device.CreateRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
socket.Connect();

I get an error of: Java.IO.IOException: read failed, socket might closed or timeout, read ret: -1

So I thought, maybe I should be using a listener instead?:
serversocket = adapter.ListenUsingRfcommWithServiceRecord(device.Name, UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
socket = serversocket.Accept();

But it hangs at serversocket.Accept(), believe me... it was stuck there for over 10 minutes until I killed the app.

To confirm I wasn't going crazy, I tested the Bluetooth device on a machine which had the manufacturers testing app installed; and it worked as expected... but not in my app.

So... what is the correct way for accessing Bluetooth without it falling over all the time?
All I want to do is listen for data being scanned by a Bluetooth device and then parse that information to one of my methods to process. Am I supposed to use both CreateRfcommSocketToServiceRecord and ListenUsingRfcommWithServiceRecord both together? Or, is the Bluetooth feature just flaky in Android???

I need to get this feature working as Zebra EMDK doesn't support non Zebra/Motorola devices, and Bluetooth would be the best go-to method if I could only get it to work.

Manifest has the following settings:
- android.permission.BLUETOOTH_ADMIN
- android.permission.BLUETOOTH
- android.permission.ACCESS_COARSE_LOCATION

Please help, this is driving me totally insane! :(


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>