How to read NFC tag data globally inside an Android Application -


I would like to read NFC tag data inside my application. Basically I have different NFC tags associated with different actions that perform inside my application. It's a bad idea to declare me intent filter inside service I do not want to associate it with any activity .

Here I appear:

  & lt; service android: name = "com .yo.helpers.NFCReaderHelper" Android: Enabled = "True" Android: export = "true" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "android.nfc.action.NDEF_DISCOVERED" /> & Lt; Category android: name = "android.intent.category.DEFAULT" /> & Lt; Data Android: scheme = "http" /> & Lt; / Intent-Filter & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "android.nfc.action.NDEF_DISCOVERED" /> & Lt; Category android: name = "android.intent.category.DEFAULT" /> & Lt; Data Android: mimeType = "text / plain" /> & Lt; / Intent-Filter & gt; & Lt; / Services & gt;   

Here is my service class:

  @override protected void handelist (intent to intent) {Log D ("योओ", "service") ; Tag mTag = null; If (intent.getAction ()! = Null) {if (intent.getAction (.) Equals ("android.nfc.action.NDEF_DISCOVERED")) log D. ("Yo", "Intention Call"); MTag = (tag) intent.getParcelableExtra (NfcAdapter.EXTRA_TAG); Logs. I ("tag id", bytefxstring (mTag.getId ()); }}   

I did not receive the call within the onHandleIntent method. If I do this within a activity , then I get intent within the onNewIntent method

You can not obtain NFC discovery intents ( NDEF_DISCOVERED , TECH_DISCOVERED with a service (or a broadcast receiver) , TAG_DISCOVERED ) On Android, NFC is designed as a means of interacting with the user and therefore, these intentions are distributed only on the activities Has been played.

A trick that you can use, is to use an invisible / transparent activity to handle the intent

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -