简体   繁体   English

从锁定屏幕点击通知时不会调用 OnNewIntent。 当通知点击锁屏时,意图未通过

[英]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.

相关问题 单击通知时,应用程序不启动或调用onNewIntent - Application not launching or calling onNewIntent when notification clicked Xamarin- MainActivity.OnNewIntent 在单击时应用程序处于后台时使用错误的参数调用推送通知 - Xamarin- MainActivity.OnNewIntent called with wrong parameters for Push Notification when App is in Background when Clicked 当用户单击通知时,通知的意图/操作未传递 - Intent/action from notification not passed on when user clicks on notification 当从 Android 的锁定屏幕单击通知操作时,如何以编程方式解锁屏幕? - How can I unlock screen programmatically when the notification action is clicked from lock screen in Android? 使用Parse.com推送通知时未调用onnewIntent方法 - onnewIntent method is not called when using Parse.com push notification 通知点击newIntent未调用 - Notification click onNewIntent not called 从通知意图通过锁屏启动活动 - Start activity over lockscreen from notification intent 单击 FCM 通知时取消 Flutter 通知挂起意图 - Flutter Notification pending intent canceled when clicked on FCM notification 从通知中调用onNewIntent() - Calling onNewIntent() from a notification ANDROID:从锁屏单击通知时生命周期无法正常工作 - ANDROID: Lifecycle not working properly when clicking notification from lockscreen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM