Share via


NfcFCardEmulation.EnableService(Activity, ComponentName) Method

Definition

Allows a foreground application to specify which card emulation service should be enabled while a specific Activity is in the foreground.

[Android.Runtime.Register("enableService", "(Landroid/app/Activity;Landroid/content/ComponentName;)Z", "", ApiSince=24)]
public bool EnableService (Android.App.Activity? activity, Android.Content.ComponentName? service);
[<Android.Runtime.Register("enableService", "(Landroid/app/Activity;Landroid/content/ComponentName;)Z", "", ApiSince=24)>]
member this.EnableService : Android.App.Activity * Android.Content.ComponentName -> bool

Parameters

activity
Activity

The activity which prefers this service to be invoked

service
ComponentName

The service to be preferred while this activity is in the foreground

Returns

whether the registration was successful

Attributes

Remarks

Allows a foreground application to specify which card emulation service should be enabled while a specific Activity is in the foreground.

The specified HCE-F service is only enabled when the corresponding application is in the foreground and this method has been called. When the application is moved to the background, #disableService(Activity) is called, or NFCID2 or System Code is replaced, the HCE-F service is disabled.

The specified Activity must currently be in resumed state. A good paradigm is to call this method in your Activity#onResume, and to call #disableService(Activity) in your Activity#onPause.

Note that this preference is not persisted by the OS, and hence must be called every time the Activity is resumed.

Java documentation for android.nfc.cardemulation.NfcFCardEmulation.enableService(android.app.Activity, android.content.ComponentName).

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