Package org.robolectric.shadows
Class ShadowNfcAdapter
java.lang.Object
org.robolectric.shadows.ShadowNfcAdapter
Shadow implementation of
NfcAdapter
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Tag
Factory method for creating a mock NfcAdapter.Tagprotected boolean
disable()
protected void
disableForegroundDispatch
(Activity activity) protected void
disableReaderMode
(Activity activity) void
dispatchTagDiscovered
(Tag tag) Dispatches the tag onto any registered readers.protected boolean
enable()
protected void
enableForegroundDispatch
(Activity activity, PendingIntent intent, IntentFilter[] filters, String[][] techLists) protected void
enableReaderMode
(Activity activity, NfcAdapter.ReaderCallback callback, int flags, Bundle extras) protected boolean
enableSecureNfc
(boolean enableSecureNfc) protected static NfcAdapter
getDefaultAdapter
(Context context) Returns last set NDEF message, or throwsIllegalStateException
if it was never set.Returns last registered callback, ornull
if none was set.protected static NfcAdapter
getNfcAdapter
(Context context) String[][]
protected boolean
boolean
Returns true if NFC is in reader mode.protected boolean
protected boolean
static void
reset()
void
setEnabled
(boolean enabled) protected void
setNdefPushMessage
(NdefMessage message, Activity activity, Activity... activities) Mocks setting NDEF push message so that it could be verified in the test.protected void
setNdefPushMessageCallback
(NfcAdapter.CreateNdefMessageCallback callback, Activity activity, Activity... activities) static void
setNfcHardwareExists
(boolean hardwareExists) Modifies the behavior ofgetNfcAdapter(Context)
to returnnull
, to simulate absence of NFC hardware.protected void
setOnNdefPushCompleteCallback
(NfcAdapter.OnNdefPushCompleteCallback callback, Activity activity, Activity... activities) Sets callback that should be used on successful Android Beam (TM).void
setSecureNfcSupported
(boolean secureNfcSupported)
-
Constructor Details
-
ShadowNfcAdapter
public ShadowNfcAdapter()
-
-
Method Details
-
getDefaultAdapter
-
getNfcAdapter
-
createMockTag
Factory method for creating a mock NfcAdapter.Tag -
enableForegroundDispatch
@Implementation protected void enableForegroundDispatch(Activity activity, PendingIntent intent, IntentFilter[] filters, String[][] techLists) -
disableForegroundDispatch
-
enableReaderMode
@Implementation protected void enableReaderMode(Activity activity, NfcAdapter.ReaderCallback callback, int flags, Bundle extras) -
disableReaderMode
-
isInReaderMode
public boolean isInReaderMode()Returns true if NFC is in reader mode. -
dispatchTagDiscovered
Dispatches the tag onto any registered readers. -
setNdefPushMessage
@Implementation protected void setNdefPushMessage(NdefMessage message, Activity activity, Activity... activities) Mocks setting NDEF push message so that it could be verified in the test. UsegetNdefPushMessage()
to verify that message was set. -
setNdefPushMessageCallback
@Implementation protected void setNdefPushMessageCallback(NfcAdapter.CreateNdefMessageCallback callback, Activity activity, Activity... activities) -
setOnNdefPushCompleteCallback
@Implementation protected void setOnNdefPushCompleteCallback(NfcAdapter.OnNdefPushCompleteCallback callback, Activity activity, Activity... activities) Sets callback that should be used on successful Android Beam (TM).The last registered callback is recalled and can be fetched using
getOnNdefPushCompleteCallback()
. -
isEnabled
-
enable
-
disable
-
isSecureNfcSupported
-
isSecureNfcEnabled
-
enableSecureNfc
-
setNfcHardwareExists
public static void setNfcHardwareExists(boolean hardwareExists) Modifies the behavior ofgetNfcAdapter(Context)
to returnnull
, to simulate absence of NFC hardware. -
setEnabled
public void setEnabled(boolean enabled) -
setSecureNfcSupported
public void setSecureNfcSupported(boolean secureNfcSupported) -
getEnabledActivity
-
getIntent
-
getFilters
-
getTechLists
-
getDisabledActivity
-
getNdefPushMessageCallback
Returns last registered callback, ornull
if none was set. -
getOnNdefPushCompleteCallback
-
getNdefPushMessage
Returns last set NDEF message, or throwsIllegalStateException
if it was never set. -
reset
-