javaemvreader exemple de code android


J'essaie de créer une application Android pour lire les données de carte de crédit / carte à puce sous la forme d'un lecteur de carte à puce Micro USB. Lorsque j'utilise cette application à partir de Google play, elle peut lire toutes les données de la carte avec succès en utilisant mon lecteur de carte: https://play.google.com/store/apps/details?id=com.scdroid.emvdemo&hl=en

Selon le site Web du développeur, ils utilisent cette bibliothèque pour créer cette application: https://code.google.com/p/javaemvreader/

, Malheureusement, j'ai essayé d'utiliser le code mais je reçois une exception de Terminal:

Sasc.terminal.TerminalException: Aucun fournisseur disponible

Mon code ressemble à ceci:

    protected void testSCReader() {
       SmartCard smartCard = null;
       CardConnection conn = null;

       try {
            conn = TerminalUtil.connect(TerminalUtil.State.CARD_PRESENT);
            if(conn == null){
               rawT.append("TerminalUtil.connect returned null");
               return;
            }
   
            SessionProcessingEnv env = new SessionProcessingEnv();
            env.setReadMasterFile(true);
            env.setProbeAllKnownAIDs(true);
            CardSession cardSession = CardSession.createSession(conn, env);

            smartCard = cardSession.initCard();

            EMVSession session = EMVSession.startSession(smartCard, conn);
            session.initContext();

            for (EMVApplication app : smartCard.getEmvApplications()) {
                    session.selectApplication(app);
                    session.initiateApplicationProcessing(); //GET PROCESSING OPTIONS + READ  RECORD(s)
                    if (!app.isInitializedOnICC()) {
                        //Skip if GPO failed (might not be a EMV card, or conditions not satisfied)
                        continue;
                    }

                    //Be VERY CAREFUL when setting this, as it WILL block the application if the PIN Try Counter reaches 0
                    //Must be combined with a PIN callback handler
                    EMVTerminal.setDoVerifyPinIfRequired(false);
                    session.prepareTransactionProcessing();
        
                    //Check if the transaction processing skipped some steps

                    if(app.getATC() == -1 || app.getLastOnlineATC() == -1) {
                        session.testReadATCData(); //ATC, Last Online ATC
                    }

                    //If PIN Try Counter has not been read, try to read it
                    if(app.getPINTryCounter() == -1) {
                        session.readPINTryCounter();
                    }

                    if(!app.isTransactionLogProcessed()) {
                        session.checkForTransactionLogRecords();
                    }
                   

                    //testGetChallenge (see if the app supports generating an unpredictable number)

                    session.testGetChallenge();

            }

            System.out.println("\n");
            System.out.println("Finished Processing card.");
            System.out.println("Now dumping card data in a more readable form:");
            System.out.println("\n");
 

            rawT.append("Finished Processing card.");

            //See the finally clause

        } catch (TerminalException ex) {
            ex.printStackTrace(System.err);
            rawT.append(ex.toString());
        } catch (UnsupportedCardException ex) {
            System.err.println("Unsupported card: " + ex.getMessage());
            rawT.append(ex.toString());
            if (conn != null) {
                //System.err.println("ATR: " + Util.prettyPrintHexNoWrap(conn.getATR()));
                System.err.println(ATR_DB.searchATR(conn.getATR()));
            }
        } catch (SmartCardException ex) {
            ex.printStackTrace(System.err);
            rawT.append(ex.toString());
        } finally {
            if (conn != null){
                try{
                    conn.disconnect(true);
                }catch(TerminalException ex){
                    ex.printStackTrace(System.err);
                }
            }
            if (smartCard != null) {
                try {
                  /* int indent = 0;
                    Log.d("FHD_DBG","======================================");
                    Log.d("FHD_DBG","             [Smart Card]             ");
                    Log.d("FHD_DBG","======================================");
                    smartCard.dump(Log.d, indent);
                    Log.d("FHD_DBG","---------------------------------------");
                    Log.d("FHD_DBG","                FINISHED               ");
                    Log.d("FHD_DBG","---------------------------------------");
                    //Log.getPrintWriter().flush();*/
                rawT.append(smartCard.toString());
                } catch (RuntimeException ex) {
                    ex.printStackTrace(System.err);
                }
                Log.d("FHD_DBG","");
            } else if (conn != null) {
            rawT.append(new sasc.iso7816.ATR(conn.getATR()).toString());
            }
        }
}
Author: FHDFRD, 2014-11-19

1 answers

J'ai reçu le même problème, java.lang.ClassNotFoundException: javax.smartcardio.TerminalFactory. C'est parce que javax.smartcardio.* n'est pas disponible dans l'environnement java fourni avec le compilateur java Android, il est disponible dans JRE.

 0
Author: TzGuru, 2015-03-06 07:48:22