package org.danielge.nfcskeleton;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.Ndef;
import android.os.Bundle;

public abstract class NdefReaderActivity extends Activity {

    private boolean readMode = false;

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        if (ndefTagFilter(intent)) {
            Ndef ndef = Ndef.get((Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG));
            NdefMessage message = ndef.getCachedNdefMessage();

            onNdefMessage(message);
        }
    }

    protected abstract void onNdefMessage (NdefMessage message);

    protected boolean ndefTagFilter (Intent intent) {
        String action = intent.getAction();
        return NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action);
    }

    protected final boolean inReadMode() {
        return readMode;
    }

    protected void enableReadTagMode(IntentFilter[] filters) {
        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
        Intent intent = new Intent(this, getClass());
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
        adapter.enableForegroundDispatch(this, pendingIntent, filters, null);

        readMode = true;
    }

    protected void disableReadTagMode() {
        readMode = false;

        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
        adapter.disableForegroundDispatch(this);
    }
}
@@ -474,16 +474,131 @@
 esume();
+%0A%0A        if (getIntent() != null && ndefTagFilter(getIntent())) %7B%0A            doNdefIntent(getIntent());%0A        %7D
 %0A    %7D%0A%0A
@@ -692,32 +692,126 @@
 (intent)) %7B%0A    
+        doNdefIntent(intent);%0A        %7D%0A    %7D%0A%0A    private void doNdefIntent(Intent intent) %7B%0A
         Ndef nde
@@ -875,28 +875,24 @@
 XTRA_TAG));%0A
-    
         Ndef
@@ -947,20 +947,16 @@
         
-    
 onNdefMe
@@ -971,26 +971,16 @@
 ssage);%0A
-        %7D%0A
     %7D%0A%0A 

Allow NdefReaderActivity to read from cold start intents