Question

I'm coding in java for my Android 2.3 Nexus S device. I'm having an issue trying to discover an NFC reader/writer that I recently purchased. In my manifest file, I'm using

<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_filter" />

All I'm trying to do is discover that some sort of NFC tech is around/available. When I bring my phone close to the NFC reader/writer, I can see the log registers some sort of event with the tags of "dalvikm" and "AudioHardware". But for some reason, the intent doesnt start my activity. My app is the only application with NFC functions - checked my defaults, etc. to make sure. In my activity, I'm simply using along with a basic layout and onCreate method:

@Override
public void onNewIntent(Intent intent) {
    // TODO
Toast.makeText(this, "NFC TECH DISCOVERED!", Toast.LENGTH_LONG).show();
}

I'd expect atleast the activity to launch. Any ideas why this isnt? Maybe because I've been waving this over an NFC reader and not an actual NFC tag which I've successfully been able to find. Thought I'm not sure why the app won't atleast acknowledge there's an NFC capable device around.

The resource file contains:

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

Solution

In "android.nfc.action.TECH_DISCOVERED" The TECH doesn't mean NFC devices it's referring to the tech on an NFC tag, ie. MifareClassic, UltraLight etc. So it won't recognise your reader/writer because it isn't a tag.

I think you're going to have a lot of trouble trying to get a desktop NFC reader/writer to communicate with the Nexus as the Nexus can't act as a tag without installing a custom ROM on it, therefore it's not able to be read or written to, and most desktop readers can't act as tags either so there's no reading or writing to them. Perhaps you could do some p2p communication but I still think this will require a lot of work.

Which NFC reader/writer do you have?

OTHER TIPS

There is also mistake in your nfc_tech_filter file. At least one of your tech-lists must be subset of techs supported by tag, which you wish to communicate with. You should use more tech-lists with fewer techs. AND and OR principle is implemented this way.

However in your case with card reader, Peanut's answer is the main problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top