Android Question NFC and ACTION_TECH_DISCOVERED intent ?

aeropic

Active Member
Licensed User
Longtime User
Hi All,

I'm playing around with some NFC tags (old ski card pass...) which are not NDEF ones.
I understood from Android APi doc that those tags should send an ACTION_TECH_DISCOVERED intend when tapped.

I therefore wanted to see if I could trap the intent with an empty activity like this one :
B4X:
#Region  Project Attributes
    #ApplicationLabel: NFC-TEST
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Globals

End Sub

Sub Process_Globals
   'Dim NFC As NFC,
   Dim LastIntent As Intent
   Dim uid As String
   Dim bytc As ByteConverter
End Sub

Sub Activity_Resume

    If Activity.GetStartingIntent = LastIntent Then Return

    LastIntent = Activity.GetStartingIntent
End Sub

I added this to the manifest:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.


AddActivityText(main, <intent-filter>
   <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="text/plain" />
</intent-filter>)

AddActivityText(main, <intent-filter>
    <action android:name="android.nfc.action.ACTION_TECH_DISCOVERED"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>)


AddActivityText(Main,<meta-data
                android:name="android.nfc.action.TECH_DISCOVERED"
                android:resource="@xml/tech_filter" />)

and I also copied a read only tech_filter.xml file in the adhoc directory :
B4X:
<?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>android.nfc.tech.NfcA</tech>
        <tech>android.nfc.tech.Ndef</tech>
        <tech>android.nfc.tech.NfcB</tech>
    </tech-list>
</resources>

Now, with all this, the results are:
- with a NDEF tag including a text record ==> the intent is received and the app is shown in the list of applications available
- with the same NDEF tag but fully erased ==> the apk does not receive the intent
- with the skypass tag ==> no reception of the intent neither

What am I doing wrong ? Please help this drives me crazy ! :eek:
 

aeropic

Active Member
Licensed User
Longtime User
You can try to uninstall these apps and then read the tag. Maybe the other apps are handling the intent.

I tried this without success.

Reading a bit on
ACTION_TECH_DISCOVERED
I understood that the xml file is a combination of AND + OR conditions. Each tech included in a node makes a AND condition . Each node is a OR condition
I tried to modify the xml file accordingly so that the NFcV (my skypass) is alone in a node.
But this also does not work.
I hear a bip which tells that the tag is read, but the activity is not launched.
B4X:
<?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-list>
    <tech-list>
        <tech>android.nfc.tech.NfcA</tech>
    </tech-list>
    <tech-list>
        <tech>android.nfc.tech.NfcV</tech>
    </tech-list>
    <tech-list>
        <tech>android.nfc.tech.NdeF</tech>
    </tech-list>
    <tech-list>
        <tech>android.nfc.tech.NfcB</tech>
    </tech-list>
  
    <tech-list>
        <tech>android.nfc.tech.MifareUltralight</tech>
    </tech-list>
      
</resources>
 
Last edited:
Upvote 0

aeropic

Active Member
Licensed User
Longtime User
Some progress: If I add this to the manifest
B4X:
AddActivityText(main,     <intent-filter>
            <action android:name="android.nfc.action.TAG_DISCOVERED"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>)
the activity is launched...
Which, if I understand the priority of NFC intents, means that either ACTION-TECH-DISCOVERED intent does not fire or (most probably) that no application catches the ACTION-TECH-DISCOVERED intent...

Well, I'm stuck again !
 
Upvote 0

aeropic

Active Member
Licensed User
Longtime User
Stupid bug .... I've found the problem in the manifest :

instead of
AddActivityText(main, <intent-filter>
<action android:name="android.nfc.action.ACTION_TECH_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>)

I should have written
AddActivityText(main, <intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>)

Now it's working very fine !
 
Last edited:
Upvote 0
Top