I wrote a simple test app to print to the clover receipt printer but it's not working. The code completes without error, the print method is called, but no job is added to the queue and nothing prints on the printer.
Here's the code I'm using... any idea?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final EditText memo = (EditText) findViewById(R.id.receipt);
final String receipt = memo.getText().toString();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Account account = CloverAccount.getAccount(MainActivity.this);
PrinterConnector pc = new PrinterConnector(MainActivity.this, account, null);
List<Printer> pl = null;
try {
pl = pc.getPrinters();
} catch (RemoteException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} catch (BindingException e) {
e.printStackTrace();
}
Printer prn = pl.get(0);
new TextPrintJob.Builder().text(receipt).build().print(MainActivity.this, account, prn);
return null;
}
@Override
protected void onPostExecute(Void s) {
super.onPostExecute(s);
Toast.makeText(MainActivity.this, "Printed.", Toast.LENGTH_LONG).show();
}
}.execute();
}
});
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}