Skip to content

Instantly share code, notes, and snippets.

@miguelcardo
Last active August 29, 2015 14:11
Show Gist options
  • Save miguelcardo/39d7e246075dc433d65b to your computer and use it in GitHub Desktop.
Save miguelcardo/39d7e246075dc433d65b to your computer and use it in GitHub Desktop.
Communicate with cardlet
protected void readCard(final IsoDep card) {
byte[] response = null;
try {
card.connect();
response = card.transceive(Utils.selectApdu(APPLICATION_ID));
card.close();
} catch (IOException e) {
Log.e(TAG, "Error reading card", e);
}
if (response != null && Arrays.equals(Utils.statusBytes(response), successfulApdu)) {
byte[] payload = Utils.responseData(response);
String printableResponse = new String();
for (int i=0; i<payload.length; i++) printableResponse += (char)payload[i];
mainMessage.setText(printableResponse);
} else {
// enable the button so the user can install the cardlet
mainMessage.setText(R.string.cardlet_not_installed);
installButton.setVisibility(View.VISIBLE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment