domguinard
domguinard

Reputation: 923

Application icon not appearing anymore when activating NFC action

I'm trying to create an Android app that can be both started by clicking on the an icon (usual way) and scanning an NFC tag. Both ways should lead to the same (main) Activity.

Turns out that it's either or for me: If I add the action NDEF_DISCOVERED for my MainActivity as well as the MAIN action (see AndroidManifest below) and re-install the app on the phone, then the app icon does not appear anywhere anymore and I can only start the app with an NFC tag.

<application
        android:label="@string/app_name"
        android:icon="@drawable/icon">
    <activity
            android:name=".activity.MainActivity"
            android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <data
                    android:host="webofthings.org"
                    android:scheme="http" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity android:name=".activity.PhotoActivity"/>
    <activity android:name=".activity.ProductDescriptionActivity"/>
</application>

Am I doing something wrong? Is that even possible or can the Main activity only be triggered by a single action? (according to the Android doc the intent-filter object can contain 1..n actions...).

Upvotes: 2

Views: 339

Answers (1)

TNR
TNR

Reputation: 5869

Change the intent filter as below:

<activity
            android:name=".activity.MainActivity"
            android:label="@string/app_name">
 <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.NDEF_DISCOVERED" />
            <data
                    android:host="webofthings.org"
                    android:scheme="http" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</activity>

Upvotes: 3

Related Questions