Reading NFC tags only from a particuar activity

旧巷老猫 提交于 2019-12-12 07:21:26

问题


Ill first tell you what I am doing. I have three activities in the sequence,

Activity1>>Activity2>>Activity3. Now I want to read NFC tags only from the Activity2 when I tap on the tag. My app should not be able to read the tags when I am in the Activity1 or Activity3. How am I supposed to this, Is there any enabling/disabling option? any property to set for the same? I dont want to prompt the user to enable/disable NFC from the Settings for this purpose.


回答1:


As a foreground application, your app will always have the chance to react first on the touched tag. So what you need to do is to enable forgraoundDsipatch for your activities, and on Activity1 and Activity3 just to ignore the event, and on Activity2 process the information of the touched tag. Otherwise if your app do not take the event of the detected tag, the android dispatch system will continue to search suitable application to trigger and when it find it it will start it on top of your app.

For more information on Foreground Dispatch look here: http://developer.android.com/guide/topics/nfc/advanced-nfc.html#foreground-dispatch




回答2:


Only set an intent-filter for whichever NFC intent you are interested in on Activity2. See the Android NFC Demo AndroidManifest.xml for an example.



来源:https://stackoverflow.com/questions/9748513/reading-nfc-tags-only-from-a-particuar-activity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!