2014-01-23 71 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