【发布时间】:2016-06-02 02:06:33
【问题描述】:
我对 Xamarin 相当陌生,并尝试了 Xamarin 开发人员网站上的不同教程。我正在测试 Android 的通知代码并收到“当前上下文中不存在上下文”错误。我将以下代码放在 MainActivity.cs 中。我该如何解决这个问题?
Notification.Builder builder = new Notification.Builder (this)
.SetContentTitle ("Sample Notification")
.SetContentText ("Hello World! This is my first notification!")
.SetSmallIcon (Resource.Drawable.ic_notification);
// Build the notification:
Notification notification = builder.Build();
// Get the notification manager:
NotificationManager notificationManager =
GetSystemService (Context.NotificationService) as NotificationManager;
// Publish the notification:
const int notificationId = 0;
notificationManager.Notify (notificationId, notification);
【问题讨论】: