Ice
Ice

Reputation: 3

Open different activity by NFC

I want to open "Activity A" when I click on icon of the app, and "Activity B" when I put tag to my phone.

I tried many different ways, for example I check intent action, but when application is closed and I put tag near phone, intent action is MAIN not TAG_DISCOVERED (and start Activity A).

How to check when application start by icon and when by NFC?

Upvotes: 0

Views: 148

Answers (1)

LaurentY
LaurentY

Reputation: 7653

In AndroidManifest for your activity open by click:

<activity
            android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

For activity open by NFC:

    <activity android:name=".NfcActivity" >
<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="text/plain" />
</intent-filter>
</activity>

Change "android.nfc.action.NDEF_DISCOVERED" with your wanted tag technology: https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#filtering-intents

Upvotes: 1

Related Questions