1

The issue I'm trying to solve is as follows:

An NFC tag will trigger my app, from which I'm launching another app. What sometimes will happen is that the NFC tag will move and will be "re discovered" by the phone and launch my app once again. The moving of the NFC tag is something I can't control.

This really ruins the experience.

What I would ideally like to do is once my app is launched, NFC triggering will be disabled or paused, and once app is closed (OnDestroy()) I will enable / un-pause NFC functionality.

I couldn't find how this could be done and your help would be really appreciated. If you have another (code related) approach on how this can be solved, this is just as good.

I noticed this post from a couple years back : NFC disable adapter But I hope there is another solution, being a system application is not an option and prompting the user the disable NFC is just as bad...

Thanks in advance.

Community
  • 1
  • 1
bergo
  • 163
  • 1
  • 13
  • Can you just get the tag to open the required app? This answer explains how that can be achieved http://stackoverflow.com/a/8671967/2737421 – Tristan Burnside Apr 13 '15 at 13:52
  • Is it sufficient to prevent re-scanning while your NFC activity is in the foreground or do you also need that while the activity that you launch through your app is in the foreground? In the latter case: Do you have control over the source code of that second app? – Michael Roland Apr 13 '15 at 20:02
  • Tristan - I already set the NFC to open my app. Michael - the latter case is what I'm trying to solve, and unfortunately the second app is a generic 3rd party app. – bergo Apr 14 '15 at 09:08

2 Answers2

1

You can create an activity-alias that handles the intent, disable it while your activity is running and re-enable it when it is destroyed.

Community
  • 1
  • 1
StenSoft
  • 9,369
  • 25
  • 30
  • Interesting work around. Not the ideal solution, but I think this is as close as you can get for "disabling" NFC functionality of the phone. – Chackle Apr 13 '15 at 15:00
  • While this method is valid, It makes more sense to use a simple Service to track both the app's state as well as the NFC's, rather than disable and enable your Activity's state. – Vaiden Apr 13 '15 at 15:01
-1

You're assuming that you can saftely turn off an important functionality of the phone, and disable any other service and/or app that is dependant on it.

This is of course wrong. You should only make assumptions regarding your own app.

So what you're really trying to do is to disable the re-launch. This can be done in many ways:

  1. Control your main Activity's launch mode, and thus your entire app's.
  2. Handle the NFC intent correctly, via a Service that monitors the NFC state as well as your app's. As per @Michael's remark - since you can only associate an NFC intent with an Activity - you would have to create a non-ui Activity (one that does not call setContentView) to act as a BroadcastListener for this Service.
  3. Tag your app, as suggested by @Tristan.
Community
  • 1
  • 1
Vaiden
  • 15,728
  • 7
  • 61
  • 91
  • NFC tag discovery intents are sent to activities only, so directly processing them through a service (as suggested in your second option) is not possible. – Michael Roland Apr 13 '15 at 20:04
  • You could easily create a non UI Activity to act as a BroadcastListener – Vaiden Apr 13 '15 at 21:29