Language

NfcAdapter.SetNdefPushMessageCallback Method

Definition

Sets a callback that dynamically generates NDEF messages to send using Android Beam.

[Android.Runtime.Register("setNdefPushMessageCallback", "(Landroid/nfc/NfcAdapter$CreateNdefMessageCallback;Landroid/app/Activity;[Landroid/app/Activity;)V", "")]
public void SetNdefPushMessageCallback(Android.Nfc.NfcAdapter.ICreateNdefMessageCallback? callback, Android.App.Activity? activity, params Android.App.Activity[]? activities);
[<Android.Runtime.Register("setNdefPushMessageCallback", "(Landroid/nfc/NfcAdapter$CreateNdefMessageCallback;Landroid/app/Activity;[Landroid/app/Activity;)V", "")>]
member this.SetNdefPushMessageCallback : Android.Nfc.NfcAdapter.ICreateNdefMessageCallback * Android.App.Activity * Android.App.Activity[] -> unit

Parameters

callback
NfcAdapter.ICreateNdefMessageCallback

The callback that creates the NDEF message, or null to clear the callback provider.

activity
Activity

The non-null activity for which the NDEF message will be pushed.

activities
Activity[]

A non-null array of additional non-null activities. Pass an empty array if there are no additional activities. Register one activity at a time from that activity's OnCreate method.

Attributes

Exceptions

The device does not support NFC.

The specified activity has already been destroyed.

On Android versions where Android Beam is functional, activity, activities, or an element of activities is null.

Remarks

Android Beam was deprecated in API level 29. On devices that support Android Beam, it remains functional through API level 33. Starting in API level 34, Android Beam is removed and calls to this method have no effect.

The callback can run only while a specified activity is resumed. Call this method before Activity.OnDestroy, preferably from Activity.OnCreate. It does not perform I/O or blocking work and is safe to call from the main thread.

Only one NDEF message can be pushed by the resumed activity. If a static message is also set with SetNdefPushMessage, this callback takes priority. Passing null clears the callback provider; a registered static message continues to be used.

Use SetNdefPushMessage when the message does not need to change. Do not pass an activity that has already reached Activity.OnDestroy.

Requires the android.Manifest.permission#NFC permission.

Android Open Source Project source documentation for android.nfc.NfcAdapter.setNdefPushMessageCallback.

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