public final class CardEmulation extends Object
These methods can be used to enable and disable card emulation, check whether card emulation is supported, query the card emulation state, customize radio frequency (RF) parameters, and set a preferred foreground application.
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static String |
CATEGORY_OTHER |
Indicates a non-payment service.
|
static String |
CATEGORY_PAYMENT |
Indicates a payment service.
|
static int |
DISABLE_MODE_A_B |
Indicates that card emulation of type A and B is disabled.
|
static int |
ENABLE_MODE_ALL |
Indicates that all types of card emulation are enabled.
|
static String |
ENABLED_SE_TYPE_ESE |
Indicates the enabled SE type is eSE.
|
static String |
ENABLED_SE_TYPE_HISEE |
Indicates the enabled SE type is hisee.
|
static int |
FEATURE_ESE |
Indicates the eSE attribute.
|
static int |
FEATURE_HCE |
Indicates the HCE attribute.
|
static int |
FEATURE_UICC |
Indicates the SIM card attribute.
|
static String |
HISEE_READY |
Indicates the hisee is ready.
|
static String |
HISEE_UNREADY |
Indicates the hisee is unready.
|
static String |
KEY_ENABLED_SE_TYPE |
Indicates the keyword used to obtain the enabled SE type.
|
static String |
KEY_HISEE_READY |
Indicates the keyword used to obtain the HISEE status.
|
static String |
KEY_RSSI_SUPPORTED |
Indicates the keyword used to obtain the status of supporting RSSI query.
|
static int |
RELEASE_PRIORITY |
Releases a preferred foreground application.
|
static String |
RSSI_QUERY_SUPPORTED |
Indicates the rssi query is supported.
|
static String |
RSSI_QUERY_UNSUPPORTED |
Indicates the rssi query is unsupported.
|
static int |
SELECTION_TYPE_ASK_IF_CONFLICT |
Indicates that the user selects a service from all available services.
|
static int |
SELECTION_TYPE_PREFER_DEFAULT |
Indicates that the default payment service is used.
|
static int |
SET_PRIORITY |
Sets a preferred foreground application.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
List<String> |
getAids(ElementName appName,
String type) |
Obtains a list of AIDs of the specified type in a given application.
|
static CardEmulation |
getInstance(NfcController controller) |
Obtains a singleton instance of the
CardEmulation class. |
String |
getNfcInfo(String key) |
Obtains the NFC information.
|
int |
getSelectionType(String category) |
Obtains the method of selecting the service based on the NFC service type.
|
boolean |
isDefaultForAid(ElementName appName,
String aid) |
Checks whether the specified application is currently the default handler for the specified AID.
|
boolean |
isDefaultForType(ElementName appName,
String type) |
Checks whether the specified application is currently the default handler for the specified type.
|
boolean |
isListenModeEnabled() |
Checks whether card emulation is enabled.
|
boolean |
isSupported(int feature) |
Checks whether a specified type of card emulation is supported.
|
boolean |
registerAids(ElementName appName,
String type,
List<String> aids) |
Registers a list of AIDs of the specified type for a given application.
|
boolean |
registerForegroundPreferred(Ability appAbility,
ElementName appName) |
Registers a preferred foreground application.
|
boolean |
removeAids(ElementName appName,
String type) |
Removes a previously registered list of AIDs of the specified type from a given application.
|
void |
setListenMode(int mode) |
Sets the card emulation mode.
|
boolean |
unregisterForegroundPreferred(Ability appAbility) |
Unregisters a preferred foreground application.
|
public static final String CATEGORY_OTHER
public static final String CATEGORY_PAYMENT
public static final int DISABLE_MODE_A_B
public static final String ENABLED_SE_TYPE_ESE
public static final String ENABLED_SE_TYPE_HISEE
public static final int ENABLE_MODE_ALL
public static final int FEATURE_ESE
This constant is used to check whether eSE card emulation is supported.
public static final int FEATURE_HCE
This constant is used to check whether HCE card emulation is supported.
public static final int FEATURE_UICC
This constant is used to check whether UICC card emulation is supported.
public static final String HISEE_READY
public static final String HISEE_UNREADY
public static final String KEY_ENABLED_SE_TYPE
public static final String KEY_HISEE_READY
public static final String KEY_RSSI_SUPPORTED
public static final int RELEASE_PRIORITY
public static final String RSSI_QUERY_SUPPORTED
public static final String RSSI_QUERY_UNSUPPORTED
public static final int SELECTION_TYPE_ASK_IF_CONFLICT
public static final int SELECTION_TYPE_PREFER_DEFAULT
public static final int SET_PRIORITY
public static CardEmulation getInstance(NfcController controller)
CardEmulation class.
If no singleton instance is available, a singleton instance will be created.
controller - Indicates the singleton instance of the NfcController class.CardEmulation instance.public boolean isSupported(int feature)
This method is used to check Whether the host or secure element supports card emulation.
feature - Indicates the card emulation type, HCE, SIM, or ESE.true if the specified type of card emulation is supported; returns
false otherwise.public void setListenMode(int mode)
mode - Indicates the card emulation mode to be set. DISABLE_MODE_A_B: Indicates
that card emulation is disabled. ENABLE_MODE_ALL: Indicates that card emulation is enabled.public boolean isListenModeEnabled()
true if card emulation is enabled; returns false otherwise.public int getSelectionType(String category)
category - Indicates the NFC service type. CATEGORY_PAYMENT indicates a payment
service, and CATEGORY_OTHER indicates a non-payment service.SELECTION_TYPE_PREFER_DEFAULT if the default payment service is used;
returns SELECTION_TYPE_ASK_IF_CONFLICT if the user selects a service from all available
services.public String getNfcInfo(String key)
This method is used to obtain the NFCC or enabled SE information.
key - Indicates the keyword of the required information. See KEY_ENABLED_SE_TYPE,
KEY_HISEE_READY, KEY_RSSI_SUPPORTED.ENABLED_SE_TYPE_ESE,
ENABLED_SE_TYPE_HISEE, HISEE_READY, HISEE_UNREADY,
RSSI_QUERY_SUPPORTED, and RSSI_QUERY_UNSUPPORTED.public boolean registerForegroundPreferred(Ability appAbility, ElementName appName)
Before using host-based card emulation (HCE) for your application in the foreground, you can call this method to register your application as a preferred application, so that it will be preferentially used when swiping card.
appAbility - Indicates the ability object of the preferred foreground application.appName - Indicates the name of the preferred foreground application.true if the registration is successful; returns false otherwise.public boolean unregisterForegroundPreferred(Ability appAbility)
Before exiting an HCE application from the foreground, you can call this method to unregister it as the preferred foreground application.
appAbility - Indicates the ability object of the preferred foreground application.true if the unregistration is successful; returns false otherwise.public boolean isDefaultForAid(ElementName appName, String aid)
appName - Indicates the name of the application to check.aid - Indicates the specified AID in a string.true if the specified application is the default handler for the specified AID;
returns false otherwise.public boolean registerAids(ElementName appName, String type, List<String> aids)
If a list of AIDs of the specified type has been registered for the application, calling this method will replace that list with a new one.
appName - Indicates the name of the application for which the list of AIDs is to be registered.type - Indicates the AID type. The value can be CATEGORY_PAYMENT or CATEGORY_OTHER.aids - Indicates the list of AIDs to register.true if the list of AIDs is registered successfully; returns false otherwise.public boolean removeAids(ElementName appName, String type)
This method only removes the AIDs that are dynamically registered using
registerAids(ohos.bundle.ElementName,java.lang.String,java.util.List), and does not remove the AIDs that are statically registered.
If dynamically registered AIDs of a specified type are removed but the statically registered ones are available
in the application, the static AID group will become active.
appName - Indicates the name of the application from which the list of AIDs is to be removed.type - Indicates the AID type. The value can be CATEGORY_PAYMENT or CATEGORY_OTHER.true if the list of AIDs is removed successfully; returns false otherwise.public List<String> getAids(ElementName appName, String type)
This method only obtains AIDs that are dynamically registered using
registerAids(ohos.bundle.ElementName,java.lang.String,java.util.List), and cannot obtain statically registered AIDs.
appName - Indicates the name of the application from which the list of AIDs is to be obtained.type - Indicates the AID type. The value can be CATEGORY_PAYMENT or CATEGORY_OTHER.public boolean isDefaultForType(ElementName appName, String type)
appName - Indicates the name of the application to check.type - Indicates the specified type in a string, including 'payment' and 'other'.true if the specified application is the default handler for the specified type;
returns false otherwise.