smartcard - javaemvreader android example code -
i trying build android application read credit card / smart card data form micro usb smart card reader. when use app google play, can read card data using card reader: https://play.google.com/store/apps/details?id=com.scdroid.emvdemo&hl=en
according developer's website use library build app: https://code.google.com/p/javaemvreader/
unfortunately tried use code in getting terminal exception :
sasc.terminal.terminalexception: no provider available
my code looks this:
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(); (emvapplication app : smartcard.getemvapplications()) { session.selectapplication(app); session.initiateapplicationprocessing(); //get processing options + read record(s) if (!app.isinitializedonicc()) { //skip if gpo failed (might not emv card, or conditions not satisfied) continue; } //be careful when setting this, block application if pin try counter reaches 0 //must combined pin callback handler emvterminal.setdoverifypinifrequired(false); session.preparetransactionprocessing(); //check if transaction processing skipped steps if(app.getatc() == -1 || app.getlastonlineatc() == -1) { session.testreadatcdata(); //atc, last online atc } //if pin try counter has not been read, try read if(app.getpintrycounter() == -1) { session.readpintrycounter(); } if(!app.istransactionlogprocessed()) { session.checkfortransactionlogrecords(); } //testgetchallenge (see if app supports generating unpredictable number) session.testgetchallenge(); } system.out.println("\n"); system.out.println("finished processing card."); system.out.println("now dumping card data in more readable form:"); system.out.println("\n"); rawt.append("finished processing card."); //see 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()); } { 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()); } } }
i received same problem, java.lang.classnotfoundexception: javax.smartcardio.terminalfactory. because javax.smartcardio.* not available in java environment comes android java compiler, available in jre.
Comments
Post a Comment