I been trying to fix this problem for a few days and still fail to fix it... Please someone can help me.
I am currently trying to develop a apps that do the same function with what starmicronic apps does. And you can find the SDK below.
http://www.starmicronics.com/support/ZipFile.aspx?sat2=195
At the start I just copy the Jar Library StarIOPort3.1.Jar into the workspace, and import to the Main.java
I tried to copy this function into my main class but at first I have missed to add the internet permission in the Manifest setting. After adding the internet permission I still get a runtime exeception of E/AndroidRuntime(776): java.lang.IllegalStateException: Could not execute method of the activity.
But it works fine with Star SDK... but not in my version.
public void PortDiscovery(View view)
{
List<PortInfo> BTPortList;
List<PortInfo> TCPPortList;
final EditText editPortName;
final ArrayList<PortInfo> arrayDiscovery;
ArrayList<String> arrayPortName;
arrayDiscovery = new ArrayList<PortInfo>();
arrayPortName = new ArrayList<String>();
try {
BTPortList = StarIOPort.searchPrinter("BT:");
TCPPortList = StarIOPort.searchPrinter("TCP:");
for (PortInfo portInfo : BTPortList) {
arrayDiscovery.add(portInfo);
}
for (PortInfo portInfo : TCPPortList) {
arrayDiscovery.add(portInfo);
}
arrayPortName = new ArrayList<String>();
for(PortInfo discovery : arrayDiscovery)
{
String portName;
portName = discovery.getPortName();
if(discovery.getMacAddress().equals("") == false)
{
portName += "\n - " + discovery.getMacAddress();
if(discovery.getModelName().equals("") == false)
{
portName += "\n - " + discovery.getModelName();
}
}
arrayPortName.add(portName);
}
} catch (StarIOPortException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
editPortName = new EditText(this);
new AlertDialog.Builder(this)
.setIcon(R.drawable.icon)
.setTitle("Please Select IP Address or Input Port Name")
.setView(editPortName)
.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int button)
{
EditText portNameField = (EditText)findViewById(R.id.editText_PortName);
portNameField.setText(editPortName.getText());
SharedPreferences pref = getSharedPreferences("pref", MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
Editor editor = pref.edit();
editor.putString("portName", portNameField.getText().toString());
editor.commit();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int button)
{
}
})
.setItems(arrayPortName.toArray(new String[0]), new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int select)
{
EditText portNameField = (EditText)findViewById(R.id.editText_PortName);
portNameField.setText(arrayDiscovery.get(select).getPortName());
SharedPreferences pref = getSharedPreferences("pref", MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
Editor editor = pref.edit();
editor.putString("portName", portNameField.getText().toString());
editor.commit();
}
})
.show();
}