使用Xam.Plugins.Notifier在Xamarin.Forms中实现本地通知

使用Xam.Plugins.Notifier在Xamarin.Forms中实现本地通知,xamarin.forms,xamarin.android,android-notifications,Xamarin.forms,Xamarin.android,Android Notifications,我已经使用Xam.Plugins.Notifier在Xamarin.Forms中实现了本地通知。我在PCL、iOS和Android中添加了Nuget软件包。 下面的代码显示通知。我在PCL中编写了下面的代码块 CrossLocalNotifications.Current.Show(“test”+“+”New test”,“Some Notification”,5,DateTime.Now.AddSeconds(8)) 我在AppDelegate.CS中添加了以下代码 if (UIDevice.

我已经使用Xam.Plugins.Notifier在Xamarin.Forms中实现了本地通知。我在PCL、iOS和Android中添加了Nuget软件包。 下面的代码显示通知。我在PCL中编写了下面的代码块

CrossLocalNotifications.Current.Show(“test”+“+”New test”,“Some Notification”,5,DateTime.Now.AddSeconds(8))

我在AppDelegate.CS中添加了以下代码

if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
        {
            // iOS 10.0+
            UNUserNotificationCenter.Current.RequestAuthorization(
                UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound,
                (approved, error) => { });

            UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();
        }
我可以在iOS中获得通知,但在Android中无法获得通知。我需要在MainActivity.cs中添加任何代码吗 有人能帮我修一下吗


仅供参考:

如文件所述,您的代码:

CrossLocalNotifications.Current.Show("test" + " " + " New test", "Some Notification", 5, DateTime.Now.AddSeconds(8));
它将在预定日期/时间显示本地通知,您的通知将在8秒延迟后显示

如果要立即显示本地通知,可以尝试使用:

CrossLocalNotifications.Current.Show("title", "body");
对我来说效果很好

更新:

您缺少显示通知的内容

根据官方文件: 对象必须包含以下内容:

  • 一个小图标,由

  • 标题,由

  • 详细信息文本,由设置


  • 参见

    嘿,谢谢你的回复。我想在8秒钟内完成。我的问题是,安卓系统没有发出通知。我是否需要像为AppDelegate.cs编写代码那样在MainActivity.cs中编写代码?你能帮我一下吗?当我调试它时,会出现这个异常。它只出现在安卓系统中,而不出现在iOS系统中。{System.NotImplementedException:未实现该方法或操作。位于Plugin.LocalNotifications.CrossLocalNotifications.get_Current()[0x00012]年:0at@SanthoshKumar,请发布完整的错误消息。@SanthoshKumar,您是如何使用
    CrossLocalNotifications.Current.Show
    方法的?请发布完整的代码。再次感谢您的回复。我没有为Droid项目添加nuget包。现在通知正在启动。这里有一个问题。为什么不要求请求允许或不允许弹出显示通知,如iOS应用程序如何要求它通过Android项目接收通知您需要在Android清单中创建一个接收器,至少使用Firebase