Search code examples
androidflutterandroid-intentnfcndef

Flutter App Cloned with Nfc App Logo when launching via Ndef intent


I want to launch my Flutter Android App automatically, after an Ndef Tag has been discovered. I'm using an Intent filter to achieve this.

All works fine, apart that when launched via the Ndef Tag, the App has an Nfc App Icon. Also, if the app was already opened manually before, it will have the App open twice:
a) The manually opened one with the correct logo
b) The Ndef Tag launched one

Screenshot with two instances of the app:

enter image description here

To exclude any side effects, I did a new Flutter project from scratch and only did the following changes in ...\android\app\src\main\AndroidManifest.xml:

Added this right after the <manifest> tag:

   <uses-permission android:name="android.permission.NFC"/>

And after the existing

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

I added this filter to launch the app:

  <intent-filter>
     <action android:name="android.nfc.action.NDEF_DISCOVERED" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:scheme="https" android:host="developer.android.com" android:pathPrefix="/test" />
   </intent-filter>

The Nfc Tag only has one record of type Uri, with the content https://developer.android.com/test

How can I avoid the app clone, and just always open the same App instance with the correct App logo?


Solution

  • Problem solved :-)

    Andrew pointed me in the right direction.

    I had to change launchMode in ...\android\app\src\main\AndroidManifest.xml:

    android:launchMode="singleTask"
    

    Andrew's link to the docs above helped me getting started.

    And this link gives the overall pig picture, how Android tasks and activities work: link