public final class NfcFCardEmulation
extends Object
| java.lang.Object | |
| android.nfc.cardemulation.NfcFCardEmulation | |
该类可用于查询NFC-F卡仿真服务的状态。 有关NFC卡仿真的一般介绍,请阅读NFC card emulation developer guide 。
该类的使用要求设备上存在 FEATURE_NFC_HOST_CARD_EMULATION_NFCF 。
公共方法(Public methods) |
|
|---|---|
boolean |
disableService(Activity activity) 禁用指定活动的服务。 |
boolean |
enableService(Activity activity, ComponentName service) 允许前台应用程序指定在特定活动处于前台时应启用哪种卡模拟服务。 |
static NfcFCardEmulation |
getInstance(NfcAdapter adapter) 助手获得这个类的一个实例。 |
String |
getNfcid2ForService(ComponentName service) 检索指定服务的当前NFCID2。 |
String |
getSystemCodeForService(ComponentName service) 检索指定服务的当前系统代码。 |
boolean |
registerSystemCodeForService(ComponentName service, String systemCode) 注册指定服务的系统代码。 |
boolean |
setNfcid2ForService(ComponentName service, String nfcid2) 为指定的服务设置NFCID2。 |
boolean |
unregisterSystemCodeForService(ComponentName service) 删除指定服务的注册系统代码。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
boolean disableService (Activity activity)
禁用指定活动的服务。
请注意,指定的活动在此次通话时仍然处于恢复状态。 调用此方法的好地方在您的onPause()实现中。
| 参数(Parameters) | |
|---|---|
activity |
Activity: The activity which the service was registered for |
| 返回(Returns) | |
|---|---|
boolean |
true when successful |
| 抛出异常(Throws) | |
|---|---|
RuntimeException |
|
boolean enableService (Activity activity, ComponentName service)
允许前台应用程序指定在特定活动处于前台时应启用哪种卡模拟服务。
指定的HCE-F服务仅在相应的应用程序处于前台且已调用此方法时才启用。 当应用程序移到后台时, disableService(Activity) ,或者替换NFCID2或系统代码,HCE-F服务被禁用。
指定的活动目前必须处于恢复状态。 一个很好的范例是调用此方法在你onResume() ,并呼吁disableService(Activity)在onPause() 。
请注意,此首选项不会由操作系统持久保存,因此每次恢复活动时都必须调用该首选项。
| 参数(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) | |
|---|---|
boolean |
whether the registration was successful |
| 抛出异常(Throws) | |
|---|---|
RuntimeException |
|
NfcFCardEmulation getInstance (NfcAdapter adapter)
助手获得这个类的一个实例。
| 参数(Parameters) | |
|---|---|
adapter |
NfcAdapter: A reference to an NfcAdapter object. |
| 返回(Returns) | |
|---|---|
NfcFCardEmulation |
|
String getNfcid2ForService (ComponentName service)
检索指定服务的当前NFCID2。
在调用setNfcid2ForService(ComponentName, String)之前,将返回Manifest文件中包含的NFCID2。 如果Manifest文件中指定了“随机”,则返回系统在安装时分配的随机数。 在用setNfcid2ForService(ComponentName, String)设置NFCID2 setNfcid2ForService(ComponentName, String) ,返回该NFCID2。
| 参数(Parameters) | |
|---|---|
service |
ComponentName: The component name of the service |
| 返回(Returns) | |
|---|---|
String |
the current NFCID2 |
| 抛出异常(Throws) | |
|---|---|
RuntimeException |
|
String getSystemCodeForService (ComponentName service)
检索指定服务的当前系统代码。
在调用registerSystemCodeForService(ComponentName, String)之前,返回Manifest文件中包含的系统代码。 在拨打registerSystemCodeForService(ComponentName, String) ,返回注册的系统代码。 在调用unregisterSystemCodeForService(ComponentName) ,返回“null”。
| 参数(Parameters) | |
|---|---|
service |
ComponentName: The component name of the service |
| 返回(Returns) | |
|---|---|
String |
the current System Code |
| 抛出异常(Throws) | |
|---|---|
RuntimeException |
|
boolean registerSystemCodeForService (ComponentName service, String systemCode)
注册指定服务的系统代码。
系统代码必须在“4000”到“4FFF”(不包括“4 * FF”)范围内。
如果之前为此服务注册了系统代码(通过清单静态地或通过使用此API动态注册),它将被替换为此服务。
即使已经为其他服务注册了相同的系统代码,该方法也能够成功注册系统代码。
请注意,您只能为与此API的调用方使用相同UID的服务注册系统代码。 通常这意味着您需要从与服务本身相同的包中调用此服务,但UID也可以在使用共享UID的包之间共享。
| 参数(Parameters) | |
|---|---|
service |
ComponentName: The component name of the service |
systemCode |
String: The System Code to be registered |
| 返回(Returns) | |
|---|---|
boolean |
whether the registration was successful. |
| 抛出异常(Throws) | |
|---|---|
RuntimeException |
|
boolean setNfcid2ForService (ComponentName service, String nfcid2)
为指定的服务设置NFCID2。
NFCID2必须在“02FE000000000000”到“02FEFFFFFFFFFFFF”的范围内。
如果之前为此服务设置了NFCID2(通过清单静态地或通过使用此API动态设置),它将被替换。
请注意,您只能将NFCID2设置为与此API的调用方使用相同UID运行的服务。 通常这意味着您需要从与服务本身相同的包中调用此服务,但UID也可以在使用共享UID的包之间共享。
| 参数(Parameters) | |
|---|---|
service |
ComponentName: The component name of the service |
nfcid2 |
String: The NFCID2 to be registered |
| 返回(Returns) | |
|---|---|
boolean |
whether the setting was successful. |
| 抛出异常(Throws) | |
|---|---|
RuntimeException |
|
boolean unregisterSystemCodeForService (ComponentName service)
删除指定服务的注册系统代码。
| 参数(Parameters) | |
|---|---|
service |
ComponentName: The component name of the service |
| 返回(Returns) | |
|---|---|
boolean |
whether the System Code was successfully removed. |
| 抛出异常(Throws) | |
|---|---|
RuntimeException |
|