英文:
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 <android.app.NotificationManager>
reason: Class<NotificationManager> 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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论