Android nfc int-filter show my application when nfc detects a tag

I am writing an application that works with NFC and MIFARE CARD.

When my NFC device detects a card, it shows me a list of applications that can use NFC, but my application is not mentioned.

What am I missing in the Android manifest file?

<uses-permission android:name="android.permission.NFC" /> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /> <application android:icon="@drawable/ic_launcher" android:allowBackup="true" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:uiOptions="splitActionBarWhenNarrow" android:name="it.namespace.app.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.TECH_DISCOVERED" /> <action android:name="android.nfc.action.TAG_DISCOVERED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/tech_filter" /> </activity> </application> 

And this is my tech_filter xml file:

  <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2" > <tech-list> <tech> android.nfc.tech.MifareClassic </tech> </tech-list> </resources> 

Here's an image showing that my application is not listed: enter image description here

+4
source share
3 answers

I had the same problem and fixed it in this sentence in android doc http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#tech-disc

β€œIf your activity filters for ACTION_TECH_DISCOVERED intent, you must create an XML resource file that indicates the technologies that your activity supports in the set of technical lists. Your activity is considered a coincidence if the set of technical lists is a subset of the technologies supported by the tag that you can get, by calling getTechList ().

For example, if the scanned tag supports MifareClassic, NdefFormatable, and NfcA, your set of technical lists should indicate all three, two, or one of the technologies (and nothing more) so that your activity is mapped. "

your nfc_tech_list should define a subset of the technogems supported by the current tag.

- Define your manifest as follows:

  <intent-filter> <action android:name="android.nfc.action.TECH_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_list" /> </activity> 

-define xml nfc_check_list:

 <?xml version="1.0" encoding="utf-8"?> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <tech-list> <tech>android.nfc.tech.NdefFormatable</tech> <tech>android.nfc.tech.MifareUltralight</tech> </tech-list> <tech-list> <tech>android.nfc.tech.NfcA</tech> <tech>android.nfc.tech.Ndef</tech> </tech-list> <tech-list> <tech>android.nfc.tech.NfcB</tech> <tech>android.nfc.tech.Ndef</tech> </tech-list> </resources> 

This will work just fine.

+11
source

Did you create a technology list resource?

From: http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#tech-disc

 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <tech-list> <tech>android.nfc.tech.IsoDep</tech> <tech>android.nfc.tech.NfcA</tech> <tech>android.nfc.tech.NfcB</tech> <tech>android.nfc.tech.NfcF</tech> <tech>android.nfc.tech.NfcV</tech> <tech>android.nfc.tech.Ndef</tech> <tech>android.nfc.tech.NdefFormatable</tech> <tech>android.nfc.tech.MifareClassic</tech> <tech>android.nfc.tech.MifareUltralight</tech> </tech-list> </resources> 

If you filter on android.nfc.action.NDEF_DISCOVERED instead of android.nfc.action.TECH_DISCOVERED, you do not need a technical list.

What you have should be transferred to the android.nfc.action.TAG_DISCOVERED file (see the flowchart on the linked page).

It is very likely that a list of applications is generated because all of these applications process NDEF_DISCOVERED. The overall intent of the NFC manager is to create an intent and deliver it to the first application that matches. The application selection is displayed only when several applications match the filter. The transition according to the flowchart looks like a comparison of stops when you can send the corresponding action.

 <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED" /> <action android:name="android.nfc.action.TECH_DISCOVERED" /> <action android:name="android.nfc.action.TAG_DISCOVERED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> 
+1
source

DO IT, ALSO REMEMBER ADD to add permission

in manifest.xml

 <uses-sdk android:minSdkVersion="12" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /> 
0
source

Source: https://habr.com/ru/post/1480359/


All Articles