Android / NFC: get tag in onCreate () without new intent

I am working on an NFC application. To run the application, I use an NDEF tag with an AAR NDEF entry inside.

It works great. But now I want to read the contents of the tag directly using the application. How can i do this?

(It already works when I remove the tag from the phone and touch it again, but I want to exclude this step.)

Update: some additional information. Well, to make this more clear, here are some parts of my current code.

private NfcAdapter nfcAdapter;
private static final int PENDING_INTENT_TECH_DISCOVERED = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_l);
    text_output = (TextView) findViewById(R.id.textView2);

    NfcAdapter adapter = ((NfcManager) getSystemService(Context.NFC_SERVICE))
            .getDefaultAdapter();       
}

@Override
public void onResume() {
    super.onResume();

    nfcAdapter = ((NfcManager) this.getSystemService(Context.NFC_SERVICE))
            .getDefaultAdapter();

    PendingIntent pi = createPendingResult(PENDING_INTENT_TECH_DISCOVERED,
            new Intent(), 0);

    nfcAdapter.enableForegroundDispatch(this, pi,
            new IntentFilter[] { new IntentFilter(
                    NfcAdapter.ACTION_TECH_DISCOVERED) }, new String[][] {
                    new String[] { "android.nfc.tech.NdefFormatable" },
                    new String[] { "android.nfc.tech.Ndef" } });
} 

@Override
public void onPause() {
    super.onPause();
    nfcAdapter.disableForegroundDispatch(this);
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
        final Intent data) {
    switch (requestCode) {
    case PENDING_INTENT_TECH_DISCOVERED:
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                doTagOperation(data);
            }
        };
        new Thread(runnable).start();

        break;
    }
}

private void doTagOperation(Intent data) {

    try {           
        String action = data.getAction();
        if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {

            Tag tag = data.getParcelableExtra(NfcAdapter.EXTRA_TAG);                                
            Ndef ndefTag = Ndef.get(tag);
        }
    } catch (Exception ex) {
                ...
    }
}

To run the application, I use AAR-NDEF-Record in the tag, which can be created as follows: NdefRecord ndr = NdefRecord.createApplicationRecord ("com.example.something");

: , , ( ), .

+2
2

NDEF , , NDEF :

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

, , NDEF:

    <intent-filter>
        <action android:name="android.nfc.action.NDEF_DISCOVERED" />
        <category android:name="android.intent.category.DEFAULT" />

URI:

        <data android:scheme="http" android:host="mroland.at" android:pathPrefix="/test" />

MIME:

        <data android:mimeType="application/vnd.mroland.test" />

NDEF , AAR ( , , , ):

        <data android:scheme="vnd.android.nfc" android:host="ext"
              android:pathPrefix="/android.com:pkg" />

. ( , , . / Android data.)

    </intent-filter>
</activity>

onCreate(), onStart(), onResume() , , getIntent().

: NDEF_DISCOVERED, NDEF AAR , MAIN LAUNCHER , . NDEF. , NDEF, NDEF_DISCOVERED. , AAR, NDEF_DISCOVERED .

+4

onNewIntent(), . onCreate() , onResume(). .

Android (http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html):

public void onPause() {
    super.onPause();
    mAdapter.disableForegroundDispatch(this);
}

public void onResume() {
    super.onResume();
    mAdapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techListsArray);
}

public void onNewIntent(Intent intent) {
    Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    //do something with tagFromIntent
}
-1

All Articles