【问题标题】:Context does not exist in current context (Android Project)当前上下文中不存在上下文(Android 项目)
【发布时间】: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);

【问题讨论】:

    标签: xamarin xamarin.android


    【解决方案1】:

    原来我不需要 Context 来访问 NotificationService。我想这是因为我已经在上下文中了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2020-03-25
      • 2019-08-05
      • 2020-07-31
      • 2021-01-16
      • 1970-01-01
      相关资源
      最近更新 更多