[NFC Plugin] How to check if NFC is active on mobile (function nfc.enabled)
Question
Forge component by Experts
Application Type
Mobile

Hello!

I've been looking for a way to check if the NFC is active in mobile and found this component.

When analyzing the code and the documentation I could see the function nfc.enabled and tried to isolate this function in a client action:


However, when tried the plugin in mobile I always receive disable status (even when turning on the NFC in mobile).

Please, could you guys give some direction if the way I'm using the plugin is correct? 

The main goal of my requirement is to send a message to the user when NFC is active (when we use QRCode and get close to NFC reader the NFC of mobile is activated and it's causing a not good user experience).


Thanks in advance and best regards,

Diego

Solution

Version 1.0.4 now includes the action to check if NFC is enabled and also the reason why is not enabled.

  • The reason will be NO_NFC if the device doesn't support NFC and NFC_DISABLED if the user has disabled NFC.


You can see the changelog for more information.

Miguel, thanks again! I tested it and worked perfectly!

Regards,

Diego

Solution

Hi Diego,

From your screenshot your doing almost everything correct. You're just missing the 

$resolve();

instruction on your callbacks like this, for example:

function isNotEnabledCb(e){
    OutSystemsNativeNFC.unregisterShareProgressCallback(progressCallback);
    $parameters.IsEnabled = false;
    $resolve();
}

function stopSharingEnabledCb() {
    OutSystemsNativeNFC.stopSharing();
    OutSystemsNativeNFC.unregisterShareProgressCallback(progressCallback);
    $parameters.IsEnabled = true;
    $resolve();
}

I'm going to  update the plugin to include that action in the next version.

Cheers,
Miguel

Hello Diego

Just To Check: Have you regenerated the application after adding this NFC Plugin? We always needs to Regenerate and application and reinstall in Phone whenever work with the Plugins. 


Please clear once before we debug in-depth. 

Thanks

Hello Manish! 

Yes, I confirm that I regenerated the application.

Thanks! =)

May I have the QR Code and OML to check? Or shall create own and see if its working! What's your thoughts 

Actually I'm just testing the NFC Sample available in forge.

Follow the OML that I'm using.

Thanks, Manish! 

NFCSample.oml

What you have in IsNFCEnabled Client action? Seems it is created by you... Please show me that. It is not included in OML


Also, it seems the CheckEnable function is not from NFC it has direct StartSharing Option that will enable the NFC. So, to check its working...

Please call StartSharing Action on click and check if your Phone Enables the NFC Automatically :)


Hope it helps 

Hi Manish!


The content of IsNFCEnabled  is in the first picture that I sent in my first post.

The content of JS is:


function isEnabledCb() {

    $parameters.Success = true;

}

function isNotEnabledCb(e){

    $parameters.Success = false;

    $parameters.Error = e;

}

nfc.enabled(isEnabledCb, isNotEnabledCb);


The nfc.enabled is part of API (https://github.com/OutSystemsExperts/phonegap-nfc#nfcenabled). My idea was create on specif client action for this function.


Thanks again! =)

Ahh, I saw in your Screenshot there is function


But it is not in mine! 


Have you installed app from Forge or created those functions self in OS? 

Hii Mate

Please see in the ShareText Action too there is one return of checking if NFC Enabled. You can use that


Let's try this first with the built-in one. Then we will try adding one client action from own in Plugin file to check the Enable. 

Yes, I create the action IsNFCEnabled.

I tried now with ShareText built-in this way:


The message returns False when NFC is off in my mobile, but there is no message when the NFC is on...

Any idea?

Thanks for your support, Manish!



I have checked and it is working fine for me. 



Please try using the app I have developed: https://personal-9qwkrkgl.outsystemscloud.com/NativeAppBuilder/App?AppKey=705201ee-a8a9-4e36-a044-da816e0426c3 


Let me know if its working 

Hi Manish! 

So, perhaps my device has any problem with NFC! =D

I tested your code in my device and it always return False.


However, my teammate has tested your app and worked well in her device. So, I suppose my device is not working well with NFC.

I thank you very much for your time, we are going to use your idea!

Best regards!

Ohh! Thank you mate :) You're Welcome..


Also, you noticed the fault in mobile phone due to this, I should have one additional thanks for that too :p :D ;) 


Take care, thanks 

Solution

Hi Diego,

From your screenshot your doing almost everything correct. You're just missing the 

$resolve();

instruction on your callbacks like this, for example:

function isNotEnabledCb(e){
    OutSystemsNativeNFC.unregisterShareProgressCallback(progressCallback);
    $parameters.IsEnabled = false;
    $resolve();
}

function stopSharingEnabledCb() {
    OutSystemsNativeNFC.stopSharing();
    OutSystemsNativeNFC.unregisterShareProgressCallback(progressCallback);
    $parameters.IsEnabled = true;
    $resolve();
}

I'm going to  update the plugin to include that action in the next version.

Cheers,
Miguel

Solution

Version 1.0.4 now includes the action to check if NFC is enabled and also the reason why is not enabled.

  • The reason will be NO_NFC if the device doesn't support NFC and NFC_DISABLED if the user has disabled NFC.


You can see the changelog for more information.

Miguel, thanks again! I tested it and worked perfectly!

Regards,

Diego

Thanks for your support, Miguel! 


I'm gonna test the new version asap.


Best regards!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.