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,提问作者Максим
相关产品推荐
相关产品推荐

