I am doing a cross platform app in which I need to print a set of data through bluetooth printer.For that i have gone through internet and found a way to print from android.Here is the code i implemented:
mBluetoothAdapter = BluetoothAdapter.DefaultAdapter;
if (mBluetoothAdapter == null)
{
await MyFavHelper.InformUser("No bluetooth adapter found", "Bluetooth");
return;
}
else
{
await MyFavHelper.InformUser("Bluetooth found", "Success");
}
if (!mBluetoothAdapter.IsEnabled)
{
mBluetoothAdapter.Enable();
}
else
{
await MyFavHelper.InformUser("Bluetooth Enabled", "Success");
}
ICollection<BluetoothDevice> pairedDevices = mBluetoothAdapter.BondedDevices;
if (pairedDevices.Count > 0)
{
foreach (BluetoothDevice device in pairedDevices)
{
if (device.Name.Contains("TSP"))
{
mmDevice = device;
break;
}
}
}
else
{
await MyFavHelper.InformUser("Paired Devices not found", "Bluetooth");
return;
}
ParcelUuid uuid = mmDevice.GetUuids().ElementAt(0);
if (mmDevice == null)
{
await MyFavHelper.InformUser("No Device Found", "Sorry");
}
mmsSocket = mmDevice.CreateInsecureRfcommSocketToServiceRecord(uuid.Uuid);
mmsSocket.Connect();
if (mmsSocket.IsConnected)
{
await MyFavHelper.InformUser("Socket Connected Successfully", "Success");
}
else
{
await MyFavHelper.InformUser("Socket Not Connected Successfully", "Sorry");
}
var datastream = mmsSocket.OutputStream;
byte[] byteArray = Encoding.ASCII.GetBytes("Sample Text");
datastream.Write(byteArray, 0, byteArray.Length);
I am successful upto "Socket connected successfully".But i am not able to print the data from printer.I am using the star micronics printer with model "TSP 100 III BI".
Can anyone please suggest me an idea if i am missing anything.
That would be a great help for me.Thanks in advance.