-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
Any chances of supporting Bluetooth classic/LE on Android/iOS platforms? #51
Comments
You can use this library to get the corresponding //For this you will need:
//using Android.Bluetooth;
private static string bluetoothPrinterAddress = "00:01:02:03:0A:0B"; //replace with your BT Address
private static Java.Util.UUID PRINTER_UUID = Java.Util.UUID.FromString("00001101-0000-1000-8000-00805F9B34FB");
private static BluetoothDevice GetDevice(BluetoothAdapter bluetoothAdapter)
{
foreach (BluetoothDevice device in bluetoothAdapter.BondedDevices)
if (device.Address == bluetoothPrinterAddress)
return device;
return null;
}
private static BluetoothSocket GetSocket(BluetoothDevice device)
{
BluetoothSocket socket = device.CreateRfcommSocketToServiceRecord(PRINTER_UUID);
socket.Connect();
return socket;
}
private static void SendData(byte[] bytes, BluetoothSocket socket)
{
var o = socket.OutputStream;
o.Write(bytes, 0, bytes.Length);
o.Close();
}
public static void Print(byte[] byteArray)
{
//Bluetooth is turned off
if (BluetoothAdapter.DefaultAdapter is null)
return;
BluetoothDevice device = GetDevice(BluetoothAdapter.DefaultAdapter);
//Printer not found
if (device is null)
return;
BluetoothSocket socket = GetSocket(device);
SendData(byteArray, socket);
} |
@igorocampos this is awesome, I would love to support this since the library supports basically all other printing types already! Do you think you could implement this as a BluetoothPrinter type like we have for the other printer types? How are you using Bluetooth from within the Android namespace, is it built against xamarin or something? I wonder if we could do this in a cross-platform way? |
@lukevp this code example was from a xamarin project alright. I don't own the devices anymore, but they were an Android POS with a BT printer embedded. But once you get the Bluetooth socket from whatever hardware you have, it should be straight forward to send the bytes over. |
Yes, this is what I was planning to implement. Just asking if there are plans to support it right in the library. Thanks for the code snippet, will definitely use this library for my purpose. Great library 😁 |
Coming back at this one again, @lukevp would you consider having 32feet as a dependency for BT comms? If yes, I think we can definitely do a cross-platform Bluetooth printer, what do you think? |
This would be the perfect package that can integrate with everything if Bluetooth classic/LE is supported. Is there a plan for that?
The text was updated successfully, but these errors were encountered: