Search code examples
androidnfcopen-nfc

the current activity only read the nfc card detected


i am creating an application which contains 2 activity. my application read the nfc tags and perform some web service calls. i need both activity can read the nfc cards. i set in intent filter of both acitivty.. but the choice dialog box will open. so i need my current activity wil read the NFC card when we touch the card to the reader. can you suggest any design methods...

this is my manifest

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:theme="@style/Theme.Jwrs">
        <activity
            android:name="MainActivity"
            android:alwaysRetainTaskState="true"
            android:label="@string/app_name"
            android:launchMode="singleInstance" >
            <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" />
            </intent-filter>
        </activity>
        <activity 
            android:name=".HomeFragmentActivity">
            <intent-filter>
                <action android:name="android.nfc.action.TAG_DISCOVERED" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

Solution

  • Use foreground mode. See my test app here.