Reputation: 6973
Hi i am developing an android application using NFC feature. Here i tried to read NFC Mifare nfc tag. I used NFCDemo which is available with android api.But i did not get success to read data through my application. In that demo that is always reading fake tags and giving fake result only.
I have a confusion about the manifest file intent filters. In my demo application is like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.nfc"
>
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
>
<activity android:name=".simulator.FakeTagsActivity"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="TagViewer"
android:theme="@android:style/Theme.NoTitleBar"
>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
</manifest>
And the application is always starting with FakeTagsActivity activity any showing list of fake tags.When we click on any one of the fake tags it will redirect to TagViewer activity with fake data not the real tag data. I have confusion too in TagViewer activity also that is resolveIntent(Intent intent) is handling always
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {}
but i am not understanding whats the wrong with this. Please advice me am i need to modify the api demo to read real tag data. Or advice me is there any other way to read the nfc tag.
I already tried This Sample but not help full for me. Please help me. Thanks in advance.
Upvotes: 1
Views: 7461
Reputation: 6973
Finally I figured out solution for my question. There we need to update the intent filter of TagViewer activity like
<activity android:name="TagViewer"
android:theme="@android:style/Theme.NoTitleBar"
>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Then I modified my if condition of TagViewer class like
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {}
It will working fine now. The main problem is priorites of TAG detection those are priority 1 : NDEF_DISCOVERED priority 2 : TECH_DISCOVERED priority 3 : TAG_DISCOVERED
I gave the priority 1 for my application intent filter then the android system always starting my activity when the tag detected.
Upvotes: 2
Reputation: 446
Check with this for NFC available or not a link and try this for reading tag details a link..... Add readind tag details code in seperate active..(eg: youractivity) and in manifest give as
<activity android:name=".youractivity"
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<data android:mimeType="text/plain"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Upvotes: 0