use of nfc.sample.nfctransaction.ui.buttons.MultiStateButtonField in project Samples-for-Java by blackberry.
the class Iso7816Command method execute.
public void execute(ReadOnlyCommandMetadata metadata, Object context) {
MultiStateButtonField btn = (MultiStateButtonField) context;
if (btn.getMsbState() == Constants.BTN_SELECT_OFF) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command exiting because button is in OFF state");
return;
}
Settings settings = Settings.getInstance();
NfcTransScreen screen = NfcTransScreen.getInstance();
Utilities.log("XXXX " + Thread.currentThread().getName() + " selecting applet");
APDUConnection apduConn = null;
// this is an example and completely proprietary APDU included solely to demonstrate the basic use of JSR-177
// Decode:
// 0x80 : CLASS = proprietary
// 0x01 : INS = invented command! Interpretation will require the selected applet to understand this command
// 0x00 : P1 = null
// 0x00 : P1 = null
byte[] command = settings.getAPDU();
try {
// Open an APDUConnection to our applet. This results in an ISO 7816-4 SELECT command being sent by the JSR-177 API
String connection_string = Utilities.makeApduConnectionString(settings.getRegisteredAIDAsString());
Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: opening APDUConnection to " + connection_string);
apduConn = (APDUConnection) Connector.open(connection_string);
Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: APDUConnection opened");
screen.setUserMessage("Selected AID OK");
// Send the APDU and wait for a response - expect an error here unless your applet supports the command that was sent
Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: sending APDU");
byte[] ret = apduConn.exchangeAPDU(command);
String resp_string = ByteArrayUtilities.byteArrayToHex(ret);
Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: response=" + resp_string);
screen.setUserMessage("APDU response=" + resp_string);
// Close the logical channel connection
apduConn.close();
} catch (Exception e) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command failed:" + e.getClass().getName() + ":" + e.getMessage());
screen.setUserMessage("Error. Select failed: check log");
}
}
Aggregations