Package nfc.sample.nfctransaction

Examples of nfc.sample.nfctransaction.Settings


        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
View Full Code Here


  }
 
  public static void registerTransactionListener(TransactionListener tl) {
     
        int pid = ApplicationManager.getApplicationManager().getProcessId(ApplicationDescriptor.currentApplicationDescriptor());
        Settings settings = Settings.getInstance();

        SecureElementManager sem = SecureElementManager.getInstance();
        if(sem == null) {
            Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " SecureElementManager instance is null - exiting");
            System.exit(0);
        }

        SecureElement[] sec_elements = null;
        try {
            sec_elements = sem.getSecureElements();
        } catch(NFCException e2) {
            e2.printStackTrace();
        }
        if(sec_elements == null) {
            Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " SecureElement[] is null - exiting");
            System.exit(0);
        }

        Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " device has " + sec_elements.length + " SEs");

        Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " getting SecureElement instance");
        SecureElement se = null;
        try {
            if(settings.isSimSeSelected()) {
                Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " Obtaining SecureElement in SIM");
                se = sem.getSecureElement(SecureElement.SIM);
            } else {
                Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " Obtaining embedded SecureElement");
                se = sem.getSecureElement(SecureElement.EMBEDDED);
            }
        } catch(NFCException e1) {
            Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " exception when getting SE: " + e1.getClass().getName() + ":" + e1.getMessage());
        }

        if(se == null) {
            Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " SecureElement is null - exiting");
            System.exit(0);
        }

        // register our app as a transaction listener
        try {
            Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " adding transaction listener for AID:"+settings.getRegisteredAIDAsString());
            se.addTransactionListener(tl, new byte[][] { settings.getRegisteredAID() });
            _tl = tl;
        } catch(NFCException e) {
            if(!e.getMessage().startsWith("TransactionListener has already been added")) {
                Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " exception when adding transaction listener: " + e.getClass().getName() + ":" + e.getMessage());
                System.exit(0);
View Full Code Here

TOP

Related Classes of nfc.sample.nfctransaction.Settings

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.