Zebra LinkOS Multiplatform SDK for Xamarin  1.1
Link-OS Portable Class Library Plugin for Xamarin
LinkOS.Plugin.Abstractions.IUsbDiscoverer Interface Reference

Discovers Zebra printers connected to an Androidâ„¢ device via USB Host More...

Inherited by LinkOS.Plugin.UsbDiscovererImplementation.

Public Member Functions

void FindPrinters (object androidContext, IDiscoveryHandler handler)
 Initiate discovery Will throw a System.NotImplementedException in iOS More...
 
bool IsZebraPrinter (object androidUSBDevice)
 Checks if a USB device is a Zebra printer Will throw a System.NotImplementedException in iOS More...
 

Detailed Description

Discovers Zebra printers connected to an Androidâ„¢ device via USB Host

///

Note:Below are 3 methods for doing discovery. They are platform specific. Do not attempt to implement all 3 methods.

using LinkOS.Plugin;
private void StartUSBDiscovery()
{
IDiscoveryEventHandler handler = DiscoveryHandlerFactory.Current.GetInstance();
handler.OnDiscoveryError += DiscoveryHandler_OnDiscoveryError;
handler.OnDiscoveryFinished += DiscoveryHandler_OnDiscoveryFinished;
handler.OnFoundPrinter += DiscoveryHandler_OnFoundPrinter;
// For Android
UsbDiscoverer.Current.FindPrinters(Xamarin.Forms.Forms.Context, handler);
// iOS products are not capable of acting as a USB host. No implemetation possible.
throw new NotImplementedException;
// For Forms apps: implement the previous two methods in OS code projects (PrinterDiscoveryImplementation.cs)
try
{
DependencyService.Get<IPrinterDiscovery>().FindUSBPrinters(handler);
}
catch (NotImplementedException)
{
System.Diagnostics.Debug.WriteLine("iOS products do not have access to USB peripherals");
}
}
private void OnFoundPrinter(IDiscoveryHandler handler, IDiscoveredPrinter discoveredPrinter)
{
Device.BeginInvokeOnMainThread(() => {
printerList.Add(discoveredPrinter);
});
}
private void OnDiscoveryError(IDiscoveryHandler handler, string message)
{
System.Diagnostics.Debug.WriteLine("Discovery Error: " + message);
}
private void OnDiscoveryFinished(IDiscoveryHandler handler, string message)
{
System.Diagnostics.Debug.WriteLine("Discovery Compete");
}
// Make sure the user has given permission to talk to USB device.
public delegate void GotPrinterHandler(IDiscoveredPrinter discoveredPrinter);
public GotPrinterHandler OnGotPrinter;
private void OnPrinterSelectedFromList(object sender, IDiscoveredPrinter discoveredPrinter)
{
if (! ((IDiscoveredPrinterUsb)discoveredPrinter).HasPermissionToCommunicate)
{
((IDiscoveredPrinterUsb)discoveredPrinter).RequestPermission(Xamarin.Forms.Forms.Context);
}
if (OnGotPrinter != null)
OnGotPrinter(discoveredPrinter);
}

Member Function Documentation

void LinkOS.Plugin.Abstractions.IUsbDiscoverer.FindPrinters ( object  androidContext,
IDiscoveryHandler  handler 
)

Initiate discovery Will throw a System.NotImplementedException in iOS

Parameters
androidContextThe android application context. set to null for iOS
handlera DiscoveryHandler instance that is used to handle discovery events (e.g. found a printer, errors, discovery finished).
bool LinkOS.Plugin.Abstractions.IUsbDiscoverer.IsZebraPrinter ( object  androidUSBDevice)

Checks if a USB device is a Zebra printer Will throw a System.NotImplementedException in iOS

Parameters
androidUSBDevicea Android.Hardware.Usb.UsbDevice
Returns
true if the USB device is a Zebra device

The documentation for this interface was generated from the following file: