无法实施 NotificationListenerService,因为清单文件中未解析 class
Unable to implement NotificationListenerService, because of unresolved class in Manifest-file
我对 Android 开发还很陌生。我正在尝试在弹出通知时更改 textView 的值的功能。
我找到了 NotificationListenerService:
https://developer.android.com/reference/android/service/notification/NotificationListenerService
第一步是将以下代码复制粘贴到清单中:
<service android:name=".NotificationListener"
android:label="@string/service_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
不幸的是,在我的清单文件中,"NotificationListenerService" 和“@string/service_name”被标记为红色,上面写着 "Unresolved class NotificationListener"。有谁知道出了什么问题?
我还没有创建 NotificatonListener-class。即使我这样做,错误也会更改为:“NotificationListener 不可分配给 'android.app.service'。
一般评论:一旦专注于红色突出显示的区域(通常),按 Alt+Enter 显示可能的解决方案。
在您的情况下,一旦应用于 "android:name=".NotificationListener",您应该能够创建扩展服务的 class,因此应该可以分配给 'android.app.service'。
然后您应该会遇到另一个标记为红色的问题 'public class NotificationListener extends Service'。再次按 Alt+Enter 并生成 'Implement methods' -> 'onBind'。
对于“@string/service_name”- 创建字符串资源或使用任何其他字符串(例如 "my_service_tag" 或其他)。
请按照附件文档查看'onListenerConnected'。干杯。
我对 Android 开发还很陌生。我正在尝试在弹出通知时更改 textView 的值的功能。 我找到了 NotificationListenerService:
https://developer.android.com/reference/android/service/notification/NotificationListenerService
第一步是将以下代码复制粘贴到清单中:
<service android:name=".NotificationListener"
android:label="@string/service_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
不幸的是,在我的清单文件中,"NotificationListenerService" 和“@string/service_name”被标记为红色,上面写着 "Unresolved class NotificationListener"。有谁知道出了什么问题?
我还没有创建 NotificatonListener-class。即使我这样做,错误也会更改为:“NotificationListener 不可分配给 'android.app.service'。
一般评论:一旦专注于红色突出显示的区域(通常),按 Alt+Enter 显示可能的解决方案。
在您的情况下,一旦应用于 "android:name=".NotificationListener",您应该能够创建扩展服务的 class,因此应该可以分配给 'android.app.service'。 然后您应该会遇到另一个标记为红色的问题 'public class NotificationListener extends Service'。再次按 Alt+Enter 并生成 'Implement methods' -> 'onBind'。
对于“@string/service_name”- 创建字符串资源或使用任何其他字符串(例如 "my_service_tag" 或其他)。
请按照附件文档查看'onListenerConnected'。干杯。