我正在尝试构建一个 android 应用程序来从 Micro USB 智能卡读卡器中读取信用卡/智能卡数据。当我从 google play 使用这个应用程序时,它可以使用我的读卡器成功读取所有卡数据: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());
}
}
}