kosbou
kosbou

Reputation: 3999

stariosdk getport failure advice needed

I have developed an app in phonegap (html5, JQuery, JS) and I want to develop a plugin to print to a BT printer.

I download printer manufacturer's SDK and I imported the appropriate .jar file to my project with all the methods I will need in my project.

I create a plugin, following an internet tutorial, in order to call from JS the JAVA methods from printer manufacturers SDK.

When i run my testing app always i receive "Failed to connect to printer".

my java code is as follow

public PluginResult execute(String action, JSONArray data, String callbackId) {


    if (NATIVE_ACTION_STRING.equals(action)) {


        this.ctx.runOnUiThread(new Runnable()
        {
            public void run()
            {
                String resultType = null;
                StarIOPort port = null;
                String message = null;
                String portName = "bt:";
                String portSettings = "mini";
                byte[] texttoprint = new byte[]{0x1b,0x74,0x0D,(byte) 0x91,(byte) 0x92,(byte) 0x93,(byte) 0x94,(byte) 0x95,(byte) 0x96,(byte) 0x97,(byte) 0x98,(byte) 0x99,0x0A,0x0A,0x0A,0x0A,0x0A};


                try 
                {
                    port = StarIOPort.getPort(portName, portSettings, 10000, (Context)ctx);

                    try
                    {
                        Thread.sleep(500);
                    }
                    catch(InterruptedException e) {}


                    port.writePort(texttoprint, 0, texttoprint.length);

                    try
                    {
                        Thread.sleep(3000);
                    }
                    catch(InterruptedException e) {}    

                }
                catch (StarIOPortException e)
                {

                    Builder dialog = new AlertDialog.Builder((Context)ctx);
                    dialog.setNegativeButton("Ok", null);
                    AlertDialog alert = dialog.create();
                    alert.setTitle("Failure");
                    alert.setMessage("Failed to connect to printer");
                    alert.show();
                }
                finally
                {
                    if(port != null)
                    {
                        try 
                        {
                            StarIOPort.releasePort(port);
                        } catch (StarIOPortException e) {}
                    }
                }
            }
        });

    }
     return null;
}}

If someone has any knowledge on StarMicronics SDK please advice.

Upvotes: 1

Views: 828

Answers (2)

Chris
Chris

Reputation: 11

Be sure to set the Bluetooth mode on your portable printer to be equivalent to the operating system your using: Bluetooth mode->Android, Bluetooth(IAP)->I-phone

Upvotes: 0

kosbou
kosbou

Reputation: 3999

add

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>

in your manifest

Upvotes: 1

Related Questions