xamarin Android通知不当行为

w41d8nur  于 2023-10-14  发布在  Android
关注(0)|答案(2)|浏览(127)

我有一个xamarin android推送通知,但当我在某些设备中收到通知时,它会保持打开状态(矩形不会自动关闭),而在其他设备中(ej Samsumg Galaxy A5),通知会自动打开(在不接触它的情况下触发其意图的活动),在其他设备中,通知工作正常。
下面是创建通知的代码

//Create notification
        var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

        // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
        var notificationId = NotificationCount;
        const int pendingIntentId = 0;
        intent.SetAction(DateTime.Now.Ticks.ToString());
        intent.AddFlags(ActivityFlags.ClearTop);
        PendingIntent pendingIntent = PendingIntent.GetActivity(this, notificationId, intent, PendingIntentFlags.UpdateCurrent);

        // Instantiate the builder and set notification elements:
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .SetContentTitle(title)
                .SetAutoCancel(true)
                .SetContentIntent(pendingIntent).SetAutoCancel(true)
                .SetContentText(payload.Message)
                .SetSmallIcon(Resource.Drawable.iconToolbarNotification)
                .SetLargeIcon(BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.IconToolbar_blue))
                .SetDefaults((int)NotificationDefaults.All)
                .SetStyle(new NotificationCompat.BigTextStyle().BigText(payload.Message));

        var fullScreenPendingIntent = PendingIntent.GetActivity(this, notificationId, intent, PendingIntentFlags.UpdateCurrent);
        builder.SetFullScreenIntent(fullScreenPendingIntent, true);

        Settings.NotificationBellAlert = true;

        // Build the notification:
        Notification notification = builder.Build();

        // Publish the notification:
        notificationManager.Notify(notificationId, notification);
wgx48brx

wgx48brx1#

PendingIntentFlags.UpdateCurrent更改为PendingIntentFlags.OneShot

ekqde3dh

ekqde3dh2#

问题是这段代码

var fullScreenPendingIntent = PendingIntent.GetActivity(this, notificationId, intent, PendingIntentFlags.UpdateCurrent);
    builder.SetFullScreenIntent(fullScreenPendingIntent, true);

感谢post

相关问题