3

I need to read an NFC TAG which is fixed at the back of the phone periodically. The problem is that android will only trigger NFC intent the first time it detects the TAG. I think that any of this two possibilities could solve the problem, but don't know if android allows any of them

1- Force Android to read NFC TAG, but I don't know if it is possible, if it is, this would be the best solution, in that case, how could i do this?

2- Turn on NFC Adapter, when it turns on it will trigger NFC detection and my activity will consume that intent, but i think it is not possible to enable/disable NFC adapter programmatically without user interaction (I need it to be automatic, opening WIFI settings is not a possibility)

Thanks!!

Mikel
  • 288
  • 4
  • 14

2 Answers2

0

Assuming your app is always in the foreground I would keep the initial Tag object in memory and periodically query the tag. If an exception is thrown when connect() is called then the tag has moved out of range.

Then set Tag object to null and listen for an intent being fired when the tag re-enters the phone's field.

griffinjm
  • 493
  • 2
  • 10
  • My app is not always in the foreground... It has a service which launches an invisible activity to work with the tag, from this activity i'd like to test if the tag is connected. – Mikel Nov 10 '14 at 11:22
  • Get a handle on the Tag object passed in the intent to the service, then pass this onto the activity and then periodically poll. – griffinjm Nov 10 '14 at 12:24
  • 2
    This isn't possible. Android's reader/writer function is disabled when the screen is off or device is locked. – S.Pols Nov 12 '14 at 14:32
  • No one said anything about the phone being locked or the screen being off, just that the app is not in the foreground. – griffinjm Jun 17 '15 at 15:31
0

It isn't possible to use Android's reader/writer mode when the screen is off or locked. Beside that there is an application that apparently can make this possible. Read this answer, it's an similar question.

Community
  • 1
  • 1
S.Pols
  • 3,414
  • 2
  • 21
  • 42
  • 1
    No one said anything about the phone being locked or the screen being off, just that the app is not in the foreground. – griffinjm Jun 17 '15 at 15:31