I am running my app in release mode.

Here is my AndroidManfiest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gmail.joelc0193.st_james_park_app">
    <application
        android:label="St James Park"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme"
            />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".SpotifyCallbackActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="${appAuthRedirectScheme}" android:host="spotify-callback" />
            </intent-filter>
        </activity>

        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

The redirect URI in question is spotify-callback.

When I delete the entry in my AndroidManifest.xml file and authenticate with Spotify, my app does not get the token back. When I put the entry back, Android gives my app twice as options. Why is this?

Also, out of the two options presented, one of them doesn't take me back to the app and just leaves me in the browser, and the other one works.

I was expecting the browser to just close and for Android to just continue with my app without being presented with my app twice as options to continue with and being made to choose one.

Edit: (Adding video) Screen recording of undesired behavior

3

There are 3 best solutions below

0
On BEST ANSWER

The issue was this line:

android:exported="true">

It should have been set to "false"

1
On

I had the same problem today. It's because of the launchMode given in your launch activity in your AndroidManifest.xml

Launch mode singleTop is the cause of your problem. In this mode, if the activity is already running, it is placed at the top of the activity stack. This means that when you return from the web view, the Android system sees two activities of the same class running, and asks you which application you want to open it on.

To solve this problem, you can use launch mode singleTask. In this mode, the activity is placed at the top of the activity stack and all other activities of the same class are removed from the stack. This means that when you return from the web view, there's only one activity of the same class running, and the Android system doesn't ask you which application you want to open it on.

From :

android:launchMode="singleTop"

To :

android:launchMode="singleTask"

0
On

This was happening to me. In my case, the problem happened because with flutter_sharing_intent package you are not suposed include the tags in manifest.xml. So, as soon as I removed tags, the problem was solved.