question

brokenoval avatar image
brokenoval asked brokenoval commented

Is there any sample code for using NFC for non payment actions?

The documentation is helpful: https://docs.clover.com/clover-platform/docs/building-with-android-nfc

And there is an old sample that seems like it should function on Mini (I don't think it does): https://github.com/clover/CustomerFacingPlatformExamples

Just wondering if there is a more up to date code sample, specifically for working with Flex using Android APIs as old as v19?
Clover Flex
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ketpat avatar image
ketpat answered brokenoval commented
We opened up NFC in Reader Writer mode on some platforms listed in https://docs.clover.com/clover-platform/docs/building-with-android-nfc . We don't have sample code, but we have tried to maintain functionality with regular Android NFC APIs so you can look up NFC app samples on the web and try them out. I will post snippets of what is essential to run an app using Android NFC on Clover devices:

Some APIs like enableReaderMode are not supported. The Activity that is reading/writing the data HAS to call enableForegroundDispatch and disableForegroundDispatch in onResume and onPause to turn on/off NFC.


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 } } }


Hope this somewhat helps for now. We will try to post samples when we have something that is easily consumable for developers.
5 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brokenoval avatar image brokenoval commented ·

Yes, this is awesome, thank you

0 Likes 0 ·
brokenoval avatar image brokenoval commented ·

@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.

0 Likes 0 ·
ketpat avatar image ketpat brokenoval commented ·

@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?

0 Likes 0 ·
ketpat avatar image ketpat brokenoval commented ·

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.

0 Likes 0 ·
brokenoval avatar image brokenoval ketpat commented ·

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.

0 Likes 0 ·
Lee Tickett avatar image
Lee Tickett answered brokenoval commented
I've not seen that page before- interesting they mention one specific NFC card being supported.
I had a feeling I had read that Clover devices do not support NFC reading other than payment cards (i.e. you need to use external devices and have them whitelisted).
1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brokenoval avatar image brokenoval commented ·

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

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community