android different result running mobile app and a copy of it
<p>I am trying to create a "hello world" style app to see how I can use some function from a BT printer SDK. So I include the SDK jar as manufacturer's manual said and I copy and paste the following code from sdk </p>

<pre><code>package com.android.test;

import android.app.*;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class HelloWorld extends Activity 
{
        /** Called when the activity is first created. */
        private static HelloWorld me;
        private String portName;
        private String portSettings;


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            me = this;
        }

        public void GetStatus(View view)
        {
        PrinterFunctions.CheckStatus(this, "bt:", "mini");
        }
    } 
</code></pre>

<p>The code from SDK is as follows</p>

<pre><code>package com.StarMicronics.StarIOSDK;

import android.app.*;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class StarIOSDKActivity extends Activity {
    /** Called when the activity is first created. */
    private static StarIOSDKActivity me;
    private String portName;
    private String portSettings;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        me = this;

        EditText portNameField = (EditText)findViewById(R.id.editText_PortName);
        portNameField.setText("BT:");

        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    public void GetStatus(View view)
    {
  /*    EditText portNameField = (EditText)findViewById(R.id.editText_PortName);
        String portName = portNameField.getText().toString();

        CheckBox portSettingsCheckBox = (CheckBox)findViewById(R.id.checkBox_PortablePrinter);
        String portSettings = "";
        if(portSettingsCheckBox.isChecked() == true)
        {
            portSettings = "mini";
        }
   */   
        //The portable printer and non portable printer have the same 
        PrinterFunctions.CheckStatus(this, "bt:", "mini");
    }
</code></pre>

<p>I have include PrinterFunctions.java at main package directory.</p>

<p>When i run SDK app the communication with the printer in completed.</p>

<p>When I run my app i receive always fail to connect to the printer.</p>

<p>What I miss?</p>

<p>PrinterFunctions.CheckStatus is as follows</p>

<pre><code>/**
 * This function checks the status of the printer
 * @param context - Activity for displaying messages to the user
 * @param portName - Port name to use for communication. This should be (TCP:&lt;IPAddress&gt;)
 * @param portSettings - Should be blank
 */
public static void CheckStatus(Context context, String portName, String portSettings)
{
    StarIOPort port = null;
    try 
    {
        /*
            using StarIOPort3.1.jar (support USB Port)
            Android OS Version: upper 2.2
        */
        port = StarIOPort.getPort(portName, portSettings, 10000, context);
        /* 
            using StarIOPort.jar
            Android OS Version: under 2.1
            port = StarIOPort.getPort(portName, portSettings, 10000);
        */

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

        StarPrinterStatus status = port.retreiveStatus();

        if(status.offline == false)
        {
            Builder dialog = new AlertDialog.Builder(context);
            dialog.setNegativeButton("Ok", null);
            AlertDialog alert = dialog.create();
            alert.setTitle("Printer");
            alert.setMessage("Printer is Online");
            alert.show();
        }
        else
        {
            String message = "Printer is offline";
            if(status.receiptPaperEmpty == true)
            {
                message += "\nPaper is Empty";
            }
            if(status.coverOpen == true)
            {
                message += "\nCover is Open";
            }
            Builder dialog = new AlertDialog.Builder(context);
            dialog.setNegativeButton("Ok", null);
            AlertDialog alert = dialog.create();
            alert.setTitle("Printer");
            alert.setMessage(message);
            alert.show();
        }
    }
    catch (StarIOPortException e)
    {
        Builder dialog = new AlertDialog.Builder(context);
        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) {}
        }
    }
}
</code></pre>
