主机卡仿真读取器模型



从阅读HCE开发人员指南的HECE开发人员指南似乎可以使用Android手机作为读者。我将卡信息放在NFC标签上,然后用手机阅读。我想让电话作为读者。你知道这是否可能吗?我创建了一个带有以下代码行的示例项目:

import android.nfc.cardemulation.HostApduService;
import android.os.Bundle;

public class MyHostAPDUService extends HostApduService{
@Override
public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
   ...
}
@Override
public void onDeactivated(int reason) {
   ...
}
}

我不知道接下来要去哪里。

我已经使用手机作为读者实现了,但通过略有不同的方法:

使用活动作为基础,我创建了一个简单的读取器应用程序,在其中我发送了一个选择,然后发送了一些关注APDUS

private NfcAdapter mAdapter;
private PendingIntent mPendingIntent;
private String[][] mTechLists;
private IsoDep card;
onCreate(){
...
mAdapter = NfcAdapter.getDefaultAdapter(this);
mPendingIntent = pendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),0);
mTechLists = new String[][]{new String[]{IsoDep.class.getName()},new String[]{IsoDep.class.getName()}};

...
}
onPause(){
mAdapter.disableForegroundDispatch(this);
}
onResume(){
mAdapter.enableForegroundDispatch(this,mPendingIntent,null,mTechLists);
}
onNewIntent(Intent intent){
Tag theTag = (Tag)intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
card = IsoDep.get(theTag);
...
card.connect();
...
byte[] response = card.transceive(apduBytes);
}

我没有做更多的工作,因为这只是一个概念证明,但我希望它有用。

最新更新