Search code examples
androidsplash-screenandroid-12android-api-31

Android 12 Splash Screen Icon Not Showing From Notification


I am using the Android 12 splash screen API and while the splash screen icon shows without issue when opening the app from the launcher, opening the app from a notification only displays the splash screen background, without the icon or animated icon.

Here's the theme in v31/styles.xml that my activity uses in AndroidManifest.xml:

<style name="MainActivityTheme" parent="AppTheme">
    <item name="android:windowSplashScreenBackground">@color/splash_screen_background</item>
    <item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_screen_icon</item>
</style>

I also tried using this other theme, but to no avail:

<style name="SplashScreenTheme" parent="Theme.SplashScreen">
    <item name="android:windowSplashScreenBackground">@color/splash_screen_background</item>
    <item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_screen_icon</item>
    <item name="postSplashScreenTheme">@style/MainActivityTheme</item>
</style>

Any idea to make the icon visible from a notification is welcome. Thanks in advance!


Solution

  • After struggling with this for a while, I found out that this is the intended behavior according to the Android team, although it's not clear exactly why, and people keep complaining about it. So I started looking into the new splashScreenStyle option in order to work around that limitation.

    Basically, I just create a new activity that forwards the pending intent from the notification to the originally intended activity while requesting the splash screen icon to display.

    1. Create NotificationLaunchActivity with theme @style/Theme.AppCompat.Translucent

    2. In the onCreate() of this activity:

       Intent intent = new Intent(this, MainActivity.class);
       intent.putExtras(getIntent());
       Bundle options = new Bundle();
       options.putInt("android.activity.splashScreenStyle", 1);
       finish(); // Must finish the activity before
       startActivity(intent, options);
      
    3. Replace MainActivity.class with NotificationLaunchActivity.class as the PendingIntent of your existing notification builders.

    And voila, simple as that. Tested on a handful of Android 12 devices and works as expected.

    NOTE: As far as I can tell, the same can be applied to display the splash screen icon when opening the app from deep links, system intents, as well as from direct share targets.