Reputation: 47
From reading the HCE developers guide here HCE Developer's Guide seems it is possible to use an android phone as a reader. I put card information on an NFC tag, and then read it with my phone. I want to have the phone act as the reader. Do you know if this is possible? I have created a sample project with the following lines of code in it:
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) {
...
}
}
I don't know where to go next.
Upvotes: 0
Views: 594
Reputation: 101
I have achieved using the phone as a reader but through a slightly different approach:
Using an activity as the base I created a simple reader application where I sent a select and then some following APDUs to a card
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);
}
I haven't done much more work on this as it was just a proof of concept but I hope it's helpful.
Upvotes: -1