当前上下文中不存在上下文(Android项目)

时间:2016-06-01 17:43:23

标签: xamarin xamarin.android

我对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);

1 个答案:

答案 0 :(得分:1)

事实证明我不需要Context来访问NotificationService。我认为这是因为我已经在上下文中了。