Android 通知不当行为

问题描述 投票:0回答:2

我有一个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);
c# android xamarin xamarin.android android-notifications
2个回答
0
投票

PendingIntentFlags.UpdateCurrent
更改为
PendingIntentFlags.OneShot


0
投票

问题出在这一段代码

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

感谢这篇帖子

© www.soinside.com 2019 - 2024. All rights reserved.