Class ShadowNfcAdapter

java.lang.Object
org.robolectric.shadows.ShadowNfcAdapter

@Implements(android.nfc.NfcAdapter.class) public class ShadowNfcAdapter extends Object
Shadow implementation of NfcAdapter.
  • Constructor Details

    • ShadowNfcAdapter

      public ShadowNfcAdapter()
  • Method Details

    • getDefaultAdapter

      @Implementation protected static NfcAdapter getDefaultAdapter(Context context)
    • getNfcAdapter

      @Implementation protected static NfcAdapter getNfcAdapter(Context context)
    • createMockTag

      public static Tag createMockTag()
      Factory method for creating a mock NfcAdapter.Tag
    • enableForegroundDispatch

      @Implementation protected void enableForegroundDispatch(Activity activity, PendingIntent intent, IntentFilter[] filters, String[][] techLists)
    • disableForegroundDispatch

      @Implementation protected void disableForegroundDispatch(Activity activity)
    • enableReaderMode

      @Implementation protected void enableReaderMode(Activity activity, NfcAdapter.ReaderCallback callback, int flags, Bundle extras)
    • disableReaderMode

      @Implementation protected void disableReaderMode(Activity activity)
    • isInReaderMode

      public boolean isInReaderMode()
      Returns true if NFC is in reader mode.
    • dispatchTagDiscovered

      public void dispatchTagDiscovered(Tag tag)
      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. Use getNdefPushMessage() 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

      @Implementation protected boolean isEnabled()
    • enable

      @Implementation protected boolean enable()
    • disable

      @Implementation protected boolean disable()
    • isSecureNfcSupported

      @Implementation(minSdk=29) protected boolean isSecureNfcSupported()
    • isSecureNfcEnabled

      @Implementation(minSdk=29) protected boolean isSecureNfcEnabled()
    • enableSecureNfc

      @Implementation(minSdk=29) protected boolean enableSecureNfc(boolean enableSecureNfc)
    • setNfcHardwareExists

      public static void setNfcHardwareExists(boolean hardwareExists)
      Modifies the behavior of getNfcAdapter(Context) to return null, to simulate absence of NFC hardware.
    • setEnabled

      public void setEnabled(boolean enabled)
    • setSecureNfcSupported

      public void setSecureNfcSupported(boolean secureNfcSupported)
    • getEnabledActivity

      public Activity getEnabledActivity()
    • getIntent

      public PendingIntent getIntent()
    • getFilters

      public IntentFilter[] getFilters()
    • getTechLists

      public String[][] getTechLists()
    • getDisabledActivity

      public Activity getDisabledActivity()
    • getNdefPushMessageCallback

      public NfcAdapter.CreateNdefMessageCallback getNdefPushMessageCallback()
      Returns last registered callback, or null if none was set.
    • getOnNdefPushCompleteCallback

      public NfcAdapter.OnNdefPushCompleteCallback getOnNdefPushCompleteCallback()
    • getNdefPushMessage

      public NdefMessage getNdefPushMessage()
      Returns last set NDEF message, or throws IllegalStateException if it was never set.
    • reset

      @Resetter public static void reset()