You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity Mobile Notifications在Android 13+无法显示问题求助

问题:Unity Mobile Notifications在Android 13及以上版本无法显示通知(Android 12正常)

问题详情

  • 现象:Unity Mobile Notifications在Android 13及更高版本无法弹出通知,但在Android 12上运行完全正常。
  • 已执行操作/排查结果:
    • 自定义清单中已添加POST_NOTIFICATION权限
    • 注册通知渠道和发送通知前,已明确发起用户权限请求
    • Logcat无错误日志,显示通知已成功注册
    • 使用的是最新版UnityMobileNotification包
  • 测试对比:将负责注册通知的脚本迁移至Unity 2022项目,调整清单及项目设置后,通知在所有Android版本均正常工作。主项目为Unity 6预览版,与Unity 2022测试项目配置看似一致,且测试项目未使用Android Resolver或自定义Gradle文件。

相关脚本

public async UniTask StartAsync(CancellationToken cancellation)
{
    await WaitPermissionAsync(_tokenSource.Token);
    
    RegisterChannel();
    ClearNotifications();
}

private void RegisterChannel()
{
    AndroidNotificationCenter.Initialize();
    var channel = new AndroidNotificationChannel()
    {
        Id = ChannelId,
        Name = "Notifications_Channel_Evolution",
        Description = "Default description",
        Importance = Importance.High,
    };

    AndroidNotificationCenter.RegisterNotificationChannel(channel);
    _notificationInitialized = true;

    Debug.Log("[Notification] Channel registered");
}

private async UniTask WaitPermissionAsync(CancellationToken token)
{
    var request = new PermissionRequest();
    await UniTask.WaitUntil(() => request.Status != PermissionStatus.RequestPending, cancellationToken: token);

    Debug.Log("[Notification] Permission perform: " + request.Status);
}

private void RegisterNotifications()
{
    if (_notificationInitialized == false)
    {
        return;
    }
    
    var calculatedTimes = CalculateNotificationTimes();
    int i = 0;
    foreach (var calculatedTime in calculatedTimes)
    {
        i++;
        
        if (i > 2)
        {
            return;
        }
        
        NotificationsType type = NotificationsType.Default;

        if (_dailyRewardClaimedObserver.GetDailyRewardStatus())
        {
            type = NotificationsType.Reward;
        }

        var notificationData = _localTextProvider.ChooseLocalKeysByRewardStatus(type)
            .GetRandomLocalText();

        var time = DateTime.Now.AddSeconds(20);

        var notification = new AndroidNotification
        {
            Title = notificationData.Item1,
            Text = notificationData.Item2,
            FireTime = time
        };

        var id = AndroidNotificationCenter.SendNotification(notification, ChannelId);
        var status = AndroidNotificationCenter.CheckScheduledNotificationStatus(id);

        Debug.Log($"[Notification] Notification {id} at {calculatedTime} is {status}");
    }

    Debug.Log("[Notification] Notifications registered");
}

内容的提问来源于stack exchange,提问作者Максим

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 00:32:42