gpt4 book ai didi

通知中未显示 Android 12 启动画面图标

转载 作者:行者123 更新时间:2023-12-05 03:17:46 35 4
gpt4 key购买 nike

我正在使用 Android 12 splash screen API虽然从启动器打开应用程序时启动画面图标显示没有问题,但从通知打开应用程序仅显示启动画面背景,没有图标或动画图标。

这是我的 Activity 在 AndroidManifest.xml 中使用的 v31/styles.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>

我也尝试过使用其他主题,但无济于事:

<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>

欢迎任何让图标在通知中可见的想法。提前致谢!

最佳答案

在为此苦苦挣扎了一段时间后,我发现这是预期的行为 according to the Android team ,尽管尚不清楚确切原因,并且人们一直在提示。因此,我开始研究新的 splashScreenStyle 选项以解决该限制。

基本上,我只是创建一个新 Activity ,将待定 Intent 从通知转发到最初预期的 Activity ,同时请求显示初始屏幕图标。

  1. 创建 NotificationLaunchActivity 主题为 @style/Theme.AppCompat.Translucent

  2. 在此 Activity 的 onCreate() 中:

     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. MainActivity.class 替换为 NotificationLaunchActivity.class 作为现有通知构建器的 PendingIntent。

瞧,就这么简单。在少数 Android 12 设备上测试并按预期工作。

注意:据我所知,当从深层链接、系统 Intent 以及 direct share targets 打开应用程序时,同样可以应用于显示启动画面图标。 .

关于通知中未显示 Android 12 启动画面图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73919563/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com