1

hy..i have a task to make my kitkat-nexus to act as a tag. I have ACS 122U as reader. i have read the program example in this site http://blog.opendatalab.de/hack/2013/11/07/android-host-card-emulation-with-acr122/. then i tryed the code on my own eclipse.

main activity :

public class MainActivity extends Activity implements OnMessageReceived, ReaderCallback {

    private NfcAdapter nfcAdapter;
    private ListView listView;
    private IsoDepAdapter isoDepAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView)findViewById(R.id.listView);
        isoDepAdapter = new IsoDepAdapter(getLayoutInflater());
        listView.setAdapter(isoDepAdapter);
        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        Log.i("end of onCreate-----","onCreate HCE");
    }

    @Override
    public void onResume() {
        super.onResume();
        //nfcAdapter.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
            //  null);

        //nfcAdapter.disableReaderMode(this); //tambahan poipo
        Log.i("onResume---", "onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
        nfcAdapter.disableReaderMode(this);
        Log.i("onPause---", "onPause");
    }

    @Override
    public void onTagDiscovered(Tag tag) {
        IsoDep isoDep = IsoDep.get(tag);
        IsoDepTransceiver transceiver = new IsoDepTransceiver(isoDep, this);
        Thread thread = new Thread(transceiver);
        Log.i("dibawah thread", "ontagdiscovered");
        thread.start();
    }

    @Override
    public void onMessage(final byte[] message) {
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                isoDepAdapter.addMessage(new String(message));
                Log.i("didlmrun---", "onMessage");
            }
        });

        Log.i("diluarrun---", "onMessage");
    }

    @Override
    public void onError(Exception exception) {
        onMessage(exception.getMessage().getBytes());
    }
}

hostapduservice :

... ... ...

@Override
    public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
        if (selectAidApdu(apdu)) {
            Log.i("HCEDEMO====", "Application selected====");
            return getWelcomeMessage();
        }
        else {
            Log.i("HCEDEMO======", "Received: =====" + new String(apdu));
            return getNextMessage();
        }
    }

... ... ...

then in the manifest file :

<uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.NFC" />
    <uses-feature android:name="FEATURE_NFC_HOST_CARD_EMULATION"/>




    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <service
            android:name=".MyHostApduService"
            android:exported="true"
            android:permission="android.permission.BIND_NFC_SERVICE" >
            <intent-filter>
                <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
            </intent-filter>

            <meta-data
                android:name="android.nfc.cardemulation.host_apdu_service"
                android:resource="@xml/apduservice" />
        </service>

         <activity
            android:name="de.grundid.hcedemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>


        </activity>





    </application>

ok,,when i ran the above source code,, i saw my acs122u blinking continously when i tapped my nexus near to it. but i didn't see the log.i(....) from hostapdu service. In the eclipse log cat, there were just some log.i from main activity. what should i do to bind that hostapdu service to main activity, so my nexus can act as a tag...??? thanks in advance... :-)

Maryadi Poipo
  • 1,418
  • 8
  • 31
  • 54
  • What application are you using to access the emulated smartcard through your ACR122U NFC reader? – Michael Roland Mar 24 '14 at 14:12
  • there is no specific application, but i will access application that has id = 2. until now, i still can't issue select application command because the reader still blinking when i tapped my nexus near to it... :-) – Maryadi Poipo Mar 25 '14 at 01:47
  • Well, most versions of the ACR122U don't work like regular PC/SC smartcard readers (and that's particularly the case when you use them in combination with other NFC devices). You typically need to have an application that sends reader specific commands to enable proper polling for the card type you expect (ISO14443-4). – Michael Roland Mar 25 '14 at 07:29
  • possible duplicate of [Reading phantom NFC tags via javax.smartcardio](http://stackoverflow.com/questions/19199875/reading-phantom-nfc-tags-via-javax-smartcardio) – Michael Roland Mar 25 '14 at 07:33
  • These two questions/answers contain some additional helpful information: [Control full APDU with NFC Software Card Emulation on Android](http://stackoverflow.com/questions/16773439/control-full-apdu-with-nfc-software-card-emulation-on-android) and [Frequent Disconnection ACR122U NFC Reader](http://stackoverflow.com/questions/21757448/frequent-disconnection-acr122u-nfc-reader) – Michael Roland Mar 25 '14 at 07:36
  • btw, i think ACR122U and my Nexus still don't pass the anticollision process..because i have checked the state of card (hce-nexus) using MFC smartcard API, and the state is "SCARD_ABSENT" {[link]http://msdn.microsoft.com/en-us/library/windows/hardware/ff549009(v=vs.85).aspx}. that is why i dont send any command according to ISO1443. am i making mistake with this...? – Maryadi Poipo Mar 25 '14 at 09:16
  • ok,,thanks for your link Michael :-) i'm gonna read that rightnow... ;-) – Maryadi Poipo Mar 25 '14 at 09:17
  • @Poipo as per the blog you have referred you will need [nfctools-examples.jar](https://github.com/grundid/nfctools-examples/releases/download/M9/nfctools-examples.jar) to test it with ACR122U card – iuq Jun 09 '14 at 13:12

0 Answers0