Reputation: 1893
I am very new to Android Development. I am trying to make functionality where the value of a textView changes when a notification pops up. I found the NotificationListenerService:
https://developer.android.com/reference/android/service/notification/NotificationListenerService
The first step is to copy-paste the following code into the manifest:
<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>
Unfortunately, in my Manifest-file "NotificationListenerService" and "@string/service_name" are marked in red, and it says "Unresolved class NotificationListener". Does anyone know what is wrong?
I have not created a NotificatonListener-class. Even when I do so the error changes to: "NotificationListener is not assignable to 'android.app.service'.
Upvotes: 0
Views: 597
Reputation: 46
General comment: hitting Alt+Enter once focused on red-highlighted area (usually) shows possible resolutions.
In your case, once applied over "android:name=".NotificationListener" you should be able to create class that extends Service, thus should be assignable to 'android.app.service'. You should then encounter another issue 'public class NotificationListener extends Service' marked red. Alt+Enter again and 'Implement methods' -> 'onBind' should be generated.
For '@string/service_name' - either create a string resource or use any other string (e.g. "my_service_tag" or whatever).
Please follow the attached docs and have a look on 'onListenerConnected'. Cheers.
Upvotes: 3