我正在为蓝牙热敏打印机做一个应用程序。我已经完成了打印部分。
这是代码:
public void printText(View view)
{
Button b = (Button)findViewById(R.id.button2);
if (b.getText().toString().equals("Choose Printer"))
errorAlert("No Printer Selected");
else
{
EditText e = (EditText)findViewById(R.id.printerText);
errorAlert("Printing...");
Intent sendIntent = new Intent();
stopService(sendIntent);
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra("MAC", mac);
sendIntent.putExtra("DATA", e.getText().toString()+"\n\n");
sendIntent.setComponent(new ComponentName("com.example.bluetoothtest",""com.example.bluetoothtest.MainActivity""));
startService(sendIntent);
}
}
当我调用 printText 时,打印机会打印两次或三次。似乎 startService(sendIntent) 触发了不止一次。