Skip to main content
Participant
June 14, 2012
Question

How to use foreground dispatch system of android NFC with AIR native extension?

  • June 14, 2012
  • 2 replies
  • 6023 views

Hello,

I'm developping an AIR application which invokes NFC on android, via AIR native extension (ANE).

I would like to enable foreground dispatch system of NFC (see http://developer.android.com/guide/topics/nfc/advanced-nfc.html#foreground-dispatch), but unfortunately it has not been achieved so far.

[Problem]

For enabling foreground dispatch system of android NFC, we need to listen some android native events e.g.) Activity.onNewIntent(), Activity.onPause() and Activity.onResume(). But I have no idea how to dispatch them to ANE. Could anyone tell me how to get it?

I know there is an available ANE for android NFC as follows:

http://code.google.com/p/ane-lab/source/browse/#svn%2Ftrunk%2Fmobile%2Fandroid%2Fjava%2Fnfc1

But it is not fit for our use case, as it just uses "intent dispatch system" (another way to use android NFC).

Maybe AIR must be extended for this case, but any information is welcome.

Thanks.

This topic has been closed for replies.

2 replies

Participating Frequently
January 24, 2013

Thanks for the trick!

This solution indeed works . Almost well.

I actually have just one little problem and i was wondering if i was the only one having it.

Tag detection works well, when a Tag is passed i get an INVOKE_EVENT and the tag ID is retrieved correctly by the ANE.

But if i pass a new TAG, i don't get the INVOKE_EVENT. To get it i have to pass the tag twice.

The first time, the phone rings, meaning the tag is correctly detected by android, but i get no invocation in the AIR side, i remove the tag, wait ~1second, pass it again, and now i get the invocation and the tag id with id.

Any idea? Is it just me or could it be an AIR bug? I'm compiling with AIR 3.5 + flex 4.6.

By the way, if anyone's interested i also found this simpler but lighter solution that could be sufficient for some people :

http://creativedrewy.blogspot.fr/2013/01/receive-nfc-data-in-adobe-air-android.html

Sorry to resurrect that old topic.

Participant
October 15, 2012

Hi, did you figure this out ?

Participant
October 16, 2012

Not yet.

In my point of view, ANE needs to provide I/F for listening these native events (such as onNewIntentListener, onPauseListener and onResumeListener) to achieve this functionality.

Participant
October 21, 2012

Hello


My name is Sadao Tokuyama.(http://twitter.com/tokufxug)


Is the person who is to manage the sample code in experimental AIR

Native Extension.


If you want to achieve the de-patch system foreground NFC, it is

necessary to consider the following points.


1.Create FREFunction for initial processing. processing of onCreate.

2.can be obtained in onResume Event.ACTIVATE. After issuing

Event.ACTIVATE, call the FREFunction to run in onResume.

3.can be obtained in onPause Event.DEACTIVATE. After issuing

Event.DEACTIVATE, call the FREFunction to run in onPause.

4.onNewIntent can be obtained at InvokeEvent.INVOKE. After issuing

InvokeEvent.INVOKE, call the FREFunction to run onNewIntent.(Gets the

Intent of the scanned NFC. : FREContext.getActivity().getIntent())


I have committed the sample code. Your reference.

http://code.google.com/p/ane-lab/source/browse/#svn%2Ftrunk%2Fmobile%2Fandroid%2Fjava%2Fnfc-foreground-dispatch


Thanks.