Merge "docs: Revised "activity launched with NFC intent" code sample to demonstrate using onNewIntent() in these situations" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0f290c9683
@@ -487,20 +487,23 @@ intent. The following example checks for the {@link android.nfc.NfcAdapter#ACTIO
|
|||||||
intent and gets the NDEF messages from an intent extra.</p>
|
intent and gets the NDEF messages from an intent extra.</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public void onResume() {
|
@Override
|
||||||
super.onResume();
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
...
|
||||||
|
if (intent != null && 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.
|
||||||
...
|
...
|
||||||
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 < rawMsgs.length; i++) {
|
|
||||||
msgs[i] = (NdefMessage) rawMsgs[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//process the msgs array
|
|
||||||
}
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>Alternatively, you can obtain a {@link android.nfc.Tag} object from the intent, which will
|
<p>Alternatively, you can obtain a {@link android.nfc.Tag} object from the intent, which will
|
||||||
|
|||||||
Reference in New Issue
Block a user