我正在尝试构建一个Android应用程序,以从Micro USB智能卡读卡器读取信用卡/智能卡数据。 当我从谷歌播放使用此应用程序时,它可以使用我的读卡器成功读取所有卡数据: https://play.google.com/store/apps/details?id=com.scdroid.emvdemo&hl=en
根据开发人员的网站,他们使用此库来构建此应用程序: https://code.google.com/p/javaemvreader/
不幸的是我尝试使用其中的代码,但我得到终端异常:
sasc.terminal.TerminalException:没有提供者
我的代码如下:
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());
}
}
}
答案 0 :(得分:0)
我收到了同样的问题,java.lang.ClassNotFoundException:javax.smartcardio.TerminalFactory。 这是因为javax.smartcardio。*在android java编译器附带的java环境中不可用,它在JRE中可用。