Android通知不当行为

时间:2018-01-12 17:06:18

标签: c# android xamarin xamarin.android android-notifications

我有一个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);

2 个答案:

答案 0 :(得分:0)

PendingIntentFlags.UpdateCurrent更改为PendingIntentFlags.OneShot

答案 1 :(得分:0)

问题是这部分代码

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

感谢这个post