Question

I am working on NFC RFID Tag reading application that needs just to read NFC ID number and write it to EditText in some NOT MAIN activity. NFC reading is just one of hundred functions in that app. When I test it on Panasonic dl1 cell phone , when I touch NFC tag to the phone for the first time phone displays me dialog with app choice to handle - only 2 app are shown "Tags" and "Starter List NFC". If I choose Starter List NFC I will be taken through long process of registering IC card and naming it and eventually - picking App that should start automatically on when Tag is close. If I choose Tags - it will display "Tag unknown" comment in the list. My application has these features and filters:

<activity
        android:name="pl.infis.spedycja.activities.LoginActivity"
        android:label="@string/app_name"
        android:theme="@style/infisTheme"
        android:windowSoftInputMode="stateUnspecified|adjustPan" >
        <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.TAG_DISCOVERED" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity>

Is there a possibility to walk around this system dialog and make it this way : when my application is running , when I bring NFC tag close to phone (no matter if first or second time) , some activity is started , then it displays NFC tag ID in edit Text and thats all ? P.S I tried with adding filter to non-Launcher activity but it didn't respond - always responded Launcher activity

Was it helpful?

Solution

The way I would probably do it, is to design a BaseActivity class that enables NFC foreground dispatching. Whenever it receives an NFC intent in onNewIntent(), it retrieves the ID of the tag and starts the relevant activity with an intent that contains the ID value.

I would then derive all my app Activities from this class. Whenever an NFC tag is scanned while the app is running, it will then receive the NFC intent automatically and dispatch it to the desired activity (which can show the tag ID).

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