[英]OnNewIntent not called when notification is hit from lock screen. And intent not passed when notification clicked on lockscreen
I built an app which when it receives notifications, launches the main activity, and passes it parameters through and intent.我构建了一个应用程序,当它接收到通知时,启动主要活动,并通过意图传递参数。 The intent is passed via the method:意图通过以下方法传递:
override void OnNewIntent(global::Android.Content.Intent intent)覆盖无效 OnNewIntent(global::Android.Content.Intent 意图)
This works well when the notification is hit while the device is not locked.这在设备未锁定时点击通知时效果很好。
But, when the notification is hit from the lock screen, the method "OnNewIntent" is not called.但是,当从锁定屏幕点击通知时,不会调用“OnNewIntent”方法。 I tried getting the intent from the "OnResume" method, but the intent is always empty.我尝试从“OnResume”方法中获取意图,但意图始终为空。
Can someone help please?有人可以帮忙吗?
Here are the flags I add in my notification intent:以下是我在通知意图中添加的标志:
intent.SetFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTop);
For my notification's pending intent, here are the flags I use:对于我的通知的待处理意图,以下是我使用的标志:
PendingIntent.GetActivity(context, pendingIntentId, intent, PendingIntentFlags.OneShot);
Your code looks good, try changing parameter context to Application.Context in the GetActivity method您的代码看起来不错,尝试在 GetActivity 方法中将参数上下文更改为 Application.Context
var requestText = _navigationSerializer.Serializer.SerializeObject(dictionary);
var intent = new Intent(Application.Context, typeof(MainActivity));
intent.AddFlags(ActivityFlags.SingleTop);
intent.PutExtra("NotificationLaunchData", requestText);
return PendingIntent.GetActivity(Application.Context, _requestCode++, intent, PendingIntentFlags.CancelCurrent);
And need to double click on the notification to open activity when device is locked.并且需要在设备锁定时双击通知以打开活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.