Android Open Source - smartcard-reader Demo Reader Xcvr






From Project

Back to project page smartcard-reader.

License

The source code is released under:

GNU General Public License

If you think the Android project smartcard-reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2014 Ryan Jones/*www. j a va 2s  .  c o m*/
 *
 * This file is part of smartcard-reader, package org.docrj.smartcard.reader.
 *
 * smartcard-reader is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * smartcard-reader is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with smartcard-reader. If not, see <http://www.gnu.org/licenses/>.
 */

package org.docrj.smartcard.reader;

import java.io.IOException;

import org.docrj.smartcard.reader.R;

import android.nfc.TagLostException;
import android.nfc.tech.IsoDep;
import android.util.Log;

public class DemoReaderXcvr extends ReaderXcvr {

    public DemoReaderXcvr(IsoDep isoDep, String aid, UiCallbacks onMessage) {
        super(isoDep, aid, onMessage);
    }

    @Override
    public void run() {
        int messageCounter = 0;
        try {
            mIsoDep.connect();
            Log.d(TAG, "select AID: " + mAid);
            mUiCallbacks.onMessageSend("00 A4 04 00"
                    + String.format("%02X ", mAidBytes.length) + mAid + " 00",
                    mContext.getString(R.string.select_app));
            byte[] response = mIsoDep.transceive(buildSelectApdu(mAidBytes));
            if (new String(response).startsWith(mContext
                    .getString(R.string.select_success_prefix))) {
                mUiCallbacks.onMessageRcv(new String(response), null, null);
                while (mIsoDep.isConnected() && !Thread.interrupted()) {
                    String message = mContext
                            .getString(R.string.reader_msg_prefix)
                            + " "
                            + messageCounter++;
                    mUiCallbacks.onMessageSend(message, mContext.getString(R.string.select_app));
                    response = mIsoDep.transceive(message.getBytes());
                    mUiCallbacks.onMessageRcv(new String(response), null, null);
                }
                mIsoDep.close();
            } else {
                mUiCallbacks.onError(mContext.getString(R.string.wrong_resp_err),
                        true);
            }
        } catch (TagLostException e) {
            mUiCallbacks
                    .onError(mContext.getString(R.string.tag_lost_err), false);
        } catch (IOException e) {
            mUiCallbacks.onError(e.getMessage(), false);
        }
    }
}




Java Source Code List

org.docrj.smartcard.emv.AppElementaryFile.java
org.docrj.smartcard.emv.AppFileLocator.java
org.docrj.smartcard.emv.AppInterchangeProfile.java
org.docrj.smartcard.emv.AppPriorityIndicator.java
org.docrj.smartcard.emv.DDF.java
org.docrj.smartcard.emv.DOL.java
org.docrj.smartcard.emv.EMVApp.java
org.docrj.smartcard.emv.EMVTags.java
org.docrj.smartcard.emv.EMVTerminal.java
org.docrj.smartcard.emv.GpoApdu.java
org.docrj.smartcard.emv.IssuerIdNumber.java
org.docrj.smartcard.emv.LanguagePref.java
org.docrj.smartcard.emv.LogEntry.java
org.docrj.smartcard.emv.MCTags.java
org.docrj.smartcard.emv.Record.java
org.docrj.smartcard.emv.TagProvider.java
org.docrj.smartcard.emv.TerminalTranQualifiers.java
org.docrj.smartcard.emv.TerminalVerifResults.java
org.docrj.smartcard.emv.VISATags.java
org.docrj.smartcard.iso7816.BERTLV.java
org.docrj.smartcard.iso7816.CommandApdu.java
org.docrj.smartcard.iso7816.ReadRecordApdu.java
org.docrj.smartcard.iso7816.ResponseApdu.java
org.docrj.smartcard.iso7816.SelectApdu.java
org.docrj.smartcard.iso7816.SmartcardException.java
org.docrj.smartcard.iso7816.TLVException.java
org.docrj.smartcard.iso7816.TLVUtil.java
org.docrj.smartcard.iso7816.TagAndLength.java
org.docrj.smartcard.iso7816.TagImpl.java
org.docrj.smartcard.iso7816.TagType.java
org.docrj.smartcard.iso7816.TagValueType.java
org.docrj.smartcard.iso7816.Tag.java
org.docrj.smartcard.reader.ApduParser.java
org.docrj.smartcard.reader.AppAdapter.java
org.docrj.smartcard.reader.DemoReaderXcvr.java
org.docrj.smartcard.reader.FileShareActivity.java
org.docrj.smartcard.reader.ManualReaderXcvr.java
org.docrj.smartcard.reader.MessageAdapter.java
org.docrj.smartcard.reader.OtherReaderXcvr.java
org.docrj.smartcard.reader.PaymentReaderXcvr.java
org.docrj.smartcard.reader.ReaderActivity.java
org.docrj.smartcard.reader.ReaderXcvr.java
org.docrj.smartcard.reader.SmartcardApp.java
org.docrj.smartcard.util.ByteArrayWrapper.java
org.docrj.smartcard.util.ISO3166_1.java
org.docrj.smartcard.util.ISO4217_Numeric.java
org.docrj.smartcard.util.Util.java