NfcAdapter.EnableForegroundDispatch Method

Definition

Enable foreground dispatch to the given Activity.

[Android.Runtime.Register("enableForegroundDispatch", "(Landroid/app/Activity;Landroid/app/PendingIntent;[Landroid/content/IntentFilter;[[Ljava/lang/String;)V", "")]
public void EnableForegroundDispatch (Android.App.Activity? activity, Android.App.PendingIntent? intent, Android.Content.IntentFilter[]? filters, string[][]? techLists);
[<Android.Runtime.Register("enableForegroundDispatch", "(Landroid/app/Activity;Landroid/app/PendingIntent;[Landroid/content/IntentFilter;[[Ljava/lang/String;)V", "")>]
member this.EnableForegroundDispatch : Android.App.Activity * Android.App.PendingIntent * Android.Content.IntentFilter[] * string[][] -> unit

Parameters

activity
Activity

the Activity to dispatch to

intent
PendingIntent

the PendingIntent to start for the dispatch

filters
IntentFilter[]

the IntentFilters to override dispatching for, or null to always dispatch

techLists
String[][]

the tech lists used to perform matching for dispatching of the NfcAdapter#ACTION_TECH_DISCOVERED intent

Attributes

Exceptions

if the Activity is not currently in the foreground

Remarks

Enable foreground dispatch to the given Activity.

This will give priority to the foreground activity when dispatching a discovered Tag to an application.

If any IntentFilters are provided to this method they are used to match dispatch Intents for both the NfcAdapter#ACTION_NDEF_DISCOVERED and NfcAdapter#ACTION_TAG_DISCOVERED. Since NfcAdapter#ACTION_TECH_DISCOVERED relies on meta data outside of the IntentFilter matching for that dispatch Intent is handled by passing in the tech lists separately. Each first level entry in the tech list represents an array of technologies that must all be present to match. If any of the first level sets match then the dispatch is routed through the given PendingIntent. In other words, the second level is ANDed together and the first level entries are ORed together.

If you pass null for both the filters and techLists parameters that acts a wild card and will cause the foreground activity to receive all tags via the NfcAdapter#ACTION_TAG_DISCOVERED intent.

This method must be called from the main thread, and only when the activity is in the foreground (resumed). Also, activities must call #disableForegroundDispatch before the completion of their Activity#onPause callback to disable foreground dispatch after it has been enabled.

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

Java documentation for android.nfc.NfcAdapter.enableForegroundDispatch(android.app.Activity, android.app.PendingIntent, android.content.IntentFilter[], java.lang.String[][]).

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