How to Understand Java API Usage for Contactless CPU Cards

From wizarPOS
Revision as of 02:58, 7 April 2021 by Mahong (talk | contribs) (Created page with "* Get RFCardReaderDevice <syntaxhighlight lang="java" line='line'> device = (RFCardReaderDevice) POSTerminal.getInstance(mContext).getDevice(POSTerminal.DEVICE_NAME_RF_CARD_...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  • Get RFCardReaderDevice
  device = (RFCardReaderDevice) POSTerminal.getInstance(mContext).getDevice(POSTerminal.DEVICE_NAME_RF_CARD_READER);
  • Open device
  device.open();
  • Search Card
  OperationListener listener = new OperationListener() {
    @Override
    public void handleResult(OperationResult arg0) {
      if (arg0.getResultCode() == OperationResult.SUCCESS) {
        sendSuccessLog2(mContext.getString(R.string.find_card_succeed));
        rfCard = ((RFCardReaderOperationResult) arg0).getCard();
      } else {
        sendFailedLog2(mContext.getString(R.string.find_card_failed));
      }
    }
  };
  device.listenForCardPresent(listener, TimeConstants.FOREVER); The result will be returned in the callback listener.
  • Communicate with Card
  CPUCard cpucard = ((CPUCard) rfCard);
  if (rfCard instanceof CPUCard) {
    ATR atr = cpucard .connect();
    result = cpucard .transmit(arryAPDU, 0);
    cpucard .disconnect();
  }
  • Close device
  device.close();