public class MainActivity extends Activity {
private NfcAdapter mAdapter; private PendingIntent mPendingIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAdapter = NfcAdapter.getDefaultAdapter(this); if (mAdapter == null) { showMessage("Error", "No NFC found on device"); finish(); return; } mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); } @Override protected void onResume() { super.onResume(); if (mAdapter != null) { mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null); } } @Override protected void onPause() { super.onPause(); if (mAdapter != null) { mAdapter.disableForegroundDispatch(this); } } @Override public void onNewIntent(Intent intent) { setIntent(intent); String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { /// Read/write data to card here } } }
@ketpat we've got this mostly working but we've run into an issue, I'm wondering if you've seen this before: We open our simple app (its a sample with just an NFC read) -> tap NFC card -> read successful -> close app (onPause function runs sucessfully) -> open Clover register app & put through a normal Clover order -> on Payment page -> tap normal NFC credit card -> Card isn't detected.
So basically after we run our NFC code it seems to disable Clover's own NFC functionality for payments. It's almost as if our onPause isn't working (but its definitely being excecuted). Alternatively I'm wondering if this is just an issue we're seeing on Sandbox and not a problem in production.
@brokenOval Can you confirm the build versions you have on Sandbox and Prod?
It is working in Prod as the build that introduced the bug isn't there on Prod. For Sandbox there were a few builds which have the issue. Since then we have patched the issue and the latest builds on Sandbox and Prod should have the fix. But the latest builds may not be pushed out to all devices.
Can you go to About Clover Flex->Check for system update and see if it downloads an OTA for you?
Actually it seems like the bug is also there on the latest build on Prod and Sandbox. The build that has the fix hasn't been rolled out yet. I believe later this month there should be an OTA that addresses this issue. I will try to push it to sandbox sooner.
OK great stuff, thank you. FYI, If it's of any interest, we discovered the the API `enableReaderMode` does in fact work on Clover Sandbox, although the documentation says it isn't allowed, this could be related.
That sample is a few years old and specifically for mini so I'm hoping it's a bit out of date. You can tap non payment nfc devices off a mini and see it recognise that something is there whilst in customer facing payment mode. So im hopeful it can work
4 People are following this question.