通知管理器的 getSystemService() 调用不起作用。

huangapple go评论86阅读模式
英文:

Notification Manager getSystemService() call not working

问题

我正在按照这个教程创建通知。

然而,我似乎无法执行以下操作:

NotificationManager notificationManager = getSystemService(NotificationManager.class);

因为我的Android Studio报告了以下错误:

所需类型:Context
提供的类型:Class <android.app.NotificationManager>
原因:Class<NotificationManager>与Context不兼容

请告诉我如何解决这个问题。

英文:

I am following this tutorial on creating notifications

However, I cannot seem to do the following:

NotificationManager notificationManager = getSystemService(NotificationManager.class);

Because my Android studio reports the error:

Required Type: Context
Provided: Class &lt;android.app.NotificationManager&gt;
reason: Class&lt;NotificationManager&gt; is not compatible with Context

Please let me know how to resolve this issue.

答案1

得分: 2

我找到了我的解决方案:

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
英文:

I found this was my solution:

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

huangapple
  • 本文由 发表于 2023年6月2日 00:32:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定