2014-01-23 75 views
0

从阅读HCE开发者在这里引导HCE Developer's Guide似乎有可能使用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) { 
    ... 
} 
} 

我不知道下一步该去哪里。

+0

您想将手机用作读卡器还是卡? –

+0

我想使用手机作为读者请。 – Sean

+0

在这种情况下,您需要查看读写器模式API(请参阅[此处](http://developer.android.com/guide/topics/connectivity/nfc/nfc.html)),查找标签调度系统和前台调度系统)。 HCE模式与您所寻找的完全相反。在主机卡模拟模式下,如同名称所示,手机充当非接触式智能**卡**而不是读卡器。 –

回答

-1

我一直在使用手机作为一个读者,而是通过一个稍微不同的方法实现:

使用为基础我创造,我送一个选择,然后一些后面的APDU到卡

一个简单的阅读器应用的活动
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); 
} 

我对此没有做太多的工作,因为这只是一个概念证明,但我希望它有帮助。

+0

嘿谢谢。这有很大帮助。你使用什么类型的卡?您是否可以向卡和手机发送接收数据? – Sean

+0

没有probs @Sean!我使用运行钱包应用程序的JavaCard。是的,我能够向其发送/接收数据,在这种情况下,我正在借记并记入JavaCard钱包小程序中的余额。所有的通信都使用APDU。 – ShortMan