Sdílet prostřednictvím


NfcAdapter.EnableForegroundNdefPush(Activity, NdefMessage) Method

Definition

Caution

deprecated

Enable NDEF message push over NFC while this Activity is in the foreground.

[Android.Runtime.Register("enableForegroundNdefPush", "(Landroid/app/Activity;Landroid/nfc/NdefMessage;)V", "")]
[System.Obsolete("deprecated")]
public void EnableForegroundNdefPush (Android.App.Activity? activity, Android.Nfc.NdefMessage? message);
[<Android.Runtime.Register("enableForegroundNdefPush", "(Landroid/app/Activity;Landroid/nfc/NdefMessage;)V", "")>]
[<System.Obsolete("deprecated")>]
member this.EnableForegroundNdefPush : Android.App.Activity * Android.Nfc.NdefMessage -> unit

Parameters

activity
Activity

foreground activity

message
NdefMessage

a NDEF Message to push over NFC

Attributes

Exceptions

if the activity is not currently in the foreground

Remarks

Enable NDEF message push over NFC while this Activity is in the foreground.

You must explicitly call this method every time the activity is resumed, and you must call #disableForegroundNdefPush before your activity completes Activity#onPause.

Strongly recommend to use the new #setNdefPushMessage instead: it automatically hooks into your activity life-cycle, so you do not need to call enable/disable in your onResume/onPause.

For NDEF push to function properly the other NFC device must support either NFC Forum's SNEP (Simple Ndef Exchange Protocol), or Android's "com.android.npp" (Ndef Push Protocol). This was optional on Gingerbread level Android NFC devices, but SNEP is mandatory on Ice-Cream-Sandwich and beyond.

This method must be called from the main thread.

<p class="note">Requires the android.Manifest.permission#NFC permission.

Java documentation for android.nfc.NfcAdapter.enableForegroundNdefPush(android.app.Activity, android.nfc.NdefMessage).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to