- Home /
Printing from an android device to wireless printer
Hi,
I have been trying to work out how to print an image to a connected wireless printer from my Unity Android app.
Here is my main script which sets up how/what to print:
public void Print(string jobName, Texture2D imageTexture,ColorModeEnum colorMode = ColorModeEnum.COLOR_MODE_COLOR,
OrientationEnum orientation = OrientationEnum.ORIENTATION_LANDSCAPE,
ScaleModeEnum scaleMode = ScaleModeEnum.SCALE_MODE_FIT )
{
AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activityContext = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass PrinterClass = new AndroidJavaClass("com.johndoe.printtest.PrinterProxyClass");
AndroidJavaObject PrinterInstance = PrinterClass.CallStatic<AndroidJavaObject>("Instance");
byte[] bytes = imageTexture.EncodeToJPG();
PrinterInstance.Call("Print",activityContext,jobName, bytes,(int)colorMode,(int)orientation,(int)scaleMode);
}
Then in a separate script, on a button press, I call the "Print" function:
PrntPlatformClass.Instance.Print("PRINT TEST",texture,c,o,s);
I've debugged both scripts and there seems to be an issue with the Call function. It gives no errors, just doesn't print.
I'm using an HP printer; I have the HP App on the device and can print normally but not through my App with this script.
Has anyone been able to print from an Android device using this method or another method?
Any help is appreciated.
Comment