Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd66ef7f authored by Kevin Hufnagle's avatar Kevin Hufnagle
Browse files

docs: Revised "activity launched with NFC intent" code sample to

demonstrate using onNewIntent() in these situations

Bug: 17129447
Change-Id: I6e60b273f8138be918708f59402866ae617af0cb
parent f032cbfa
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -487,19 +487,22 @@ intent. The following example checks for the {@link android.nfc.NfcAdapter#ACTIO
intent and gets the NDEF messages from an intent extra.</p>

<pre>
public void onResume() {
    super.onResume();
&#64;Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    ...
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        if (rawMsgs != null) {
            msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i &lt; rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];
    if (intent != null &amp;&amp; NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        Parcelable[] rawMessages =
            intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        if (rawMessages != null) {
            NdefMessage[] messages = new NdefMessage[rawMessages.length];
            for (int i = 0; i < rawMessages.length; i++) {
                messages[i] = (NdefMessage) rawMessages[i];
            }
            // Process the messages array.
            ...
        }
    }
    //process the msgs array
}
</pre>