所有手机如何与卡通信(Iso 14443 Type B,Tech:IsoDep& NfcB)支持NFC

时间:2015-01-15 04:10:23

标签: android android-intent nfc apdu

我正在制作Android应用程序来传达Ezlink卡(Iso 14443 Type B,Tech:IsoDep& NfcB)。 我的问题是应用程序无法获取钱包数据(卡号,平衡),调用isoDep.transceive()后总是得到6A82。我用HTC One X(OS 4.2.2)测试了一些设备,它运行成功,但三星S3(OS 4.1.2)和一些设备(OS 4.4.2),如三星s4,s5 ......他们总是得到6A82。 / p>

public class NFCActivity extends Activity {
    private NfcAdapter mNfcAdapter;
    private QRCode qrCode;
    private WebserviceConnection wsConnection;
    private ConnectionDetector cd;
    private boolean detectCard;
    private SharedPreferences sharedpreferences;
    private ProgressDialog dialog;
    private TextView error_content;
    private TextView error;
    private IsoDepReaderTask isoDepReaderTask;
    PendingIntent pendingIntent;
    IntentFilter[] filters;
    String[][] techList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tabcard);
        Log.d("onCreate() NFCActivity","123456");
        qrCode = new QRCode();
        isoDepReaderTask = new IsoDepReaderTask(this);
        wsConnection = new WebserviceConnection(this);
        cd = new ConnectionDetector(this);
        sharedpreferences = getSharedPreferences("MyPref", Context.MODE_PRIVATE);
        error = (TextView) findViewById(R.id.error);
        error_content = (TextView) findViewById(R.id.error_content);

        pendingIntent = PendingIntent.getActivity(
                this, 0, new Intent(this, getClass()).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
        filters = new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) };
        techList = new String[][] {new String[] { IsoDep.class.getName() } };

        mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
        // get the Intent that started this Activity
        Intent in = getIntent();
        // get the Bundle that stores the data of this Activity
        Bundle b = in.getExtras();
        // getting data from bundle
        String contents = b.getString("Contents");
        if(contents != null) {
            qrCode.getQRCodeDetail(contents);
        }

        handleIntent(in);
    }


    @Override
    protected void onResume() {
        super.onResume();
        cd.ensureSensorIsOn();
        mNfcAdapter.enableForegroundDispatch(this, pendingIntent, filters, techList);
        isoDepReaderTask.countDownTimeConnectToCard();
    }

    @Override
    protected void onPause() {
        mNfcAdapter.disableForegroundDispatch(this);
        super.onPause();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        handleIntent(intent);
    }

    private void handleIntent(Intent intent) {
        String action = intent.getAction();
        if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
            dialog = ProgressDialog.show(NFCActivity.this, "Please hold on to your card", "Scanning...", true);
            detectCard = true;
            // In case we would still use the Tech Discovered Intent
            Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
//          new IsoDepReaderTask().execute(tag);

            isoDepReaderTask = new IsoDepReaderTask(this, sharedpreferences, qrCode, dialog);
            isoDepReaderTask.execute(tag);
            //Log.d(" STEP1 NFC not connected",  ""+ IsoDepReaderTask.isoDep.isConnected());
        }
    }
    // if within 1 minute that device cannot communicate with card then showing a Toast
    private void countDownTimeConnectToCard() {
        final Toast toast =  Toast.makeText(this, R.string.error_detect, Toast.LENGTH_LONG);
            new CountDownTimer(60000, 15000) {
                public void onTick(long millisUntilFinished) {
                    Log.d("detectCard", String.valueOf(detectCard));
                    if(!detectCard && millisUntilFinished < 50000) {
                        toast.show();
                    }
                }
                public void onFinish() {
                    if(!detectCard) {
                        error.setVisibility(View.VISIBLE);
                        error_content.setText(R.string.no_card_detected);
                    }
                }
            }.start();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

在使用我上面提到的一些设备调用isoDep.transceive(purseByte)后,我总是得到6A82。

//IsoDepReaderTask class
IsoDep isoDep = IsoDep.get(tag);
        if (isoDep != null) {
            try {
                if (!isoDep.isConnected()) {
                    isoDep.connect();
                }
                isoDep.setTimeout(5000);

            byte[] getChallengeByte = { (byte) 0x00, (byte) 0x84,
                    (byte) 0x00, (byte) 0x00, (byte) 0x08 };
            byte[] challengeResult = isoDep.transceive(getChallengeByte);

            String purseString = "903203000A1403CF549C2B7520389C");
            byte[] purseByte = common.hexStringToByteArray(purseString.toString());
            byte[] purseResult = isoDep.transceive(purseByte);
            String purseData = common.hexString(purseResult);

任何人都有关于我的问题的经验可以帮助我。非常感谢。
PS:如果我使用 EnableReaderMode ,我可以使用一些带有OS 4.4.2的Android手机与卡通信,但是当实现ReaderCallback时,该应用程序只能使用API​​ 19.我喜欢我的应用程序工作每个手机都可以支持NFC

0 个答案:

没有答案