几天来我一直在尝试解决此问题,但仍然无法解决...请有人可以帮助我。
我目前正在尝试开发一个与starmicronic 应用程序具有相同功能的应用程序。您可以在下面找到 SDK。
http://www.starmicronics.com/support/ZipFile.aspx?sat2=195
一开始我只是将 Jar Library StarIOPort3.1.Jar 复制到工作区,然后导入到 Main.java
我试图将此功能复制到我的主类中,但起初我错过了在清单设置中添加互联网权限。添加互联网权限后,我仍然得到 E/AndroidRuntime(776) 的运行时异常:java.lang.IllegalStateException:无法执行活动的方法。
但它适用于 Star SDK……但不适用于我的版本。
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();
}